|
Boost Users : |
From: Angus Leeming (angus.leeming_at_[hidden])
Date: 2006-01-20 07:59:10
Sebastian Redl wrote:
> Aaron Griffin wrote:
>
>>std::string get_env(std::string const& name)
>>{
>> char* var = getenv(name.c_str());
>> //getenv can return NULL, std::string(NULL) throws
>> if(var) return var;
>> else return "";
>>}
>>
>>
> An empty environment variable is not exactly the same as a non-existent
> one. Perhaps like this:
> boost::optional<std::string> get_env(std::string const &name)
> {
> char *var = getenv(name.c_str());
> if(var) return var;
> else return boost::nothing;
> }
Here's some GPL-ed code to set and get environment variables that works on
both *nix and Windows:
http://www.lyx.org/cgi-bin/viewcvs.cgi/lyx-devel/src/support/environment.C?rev=HEAD&content-type=text/vnd.viewcvs-markup
Equivalent url: http://tinyurl.co.uk/o5jo
Of course, as Sebastian points out, boost::optional would be more
elegant/correct for the getenv wrapper.
HTH,
Angus
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net