Re: getenv

new topic     » goto parent     » topic index » view thread      » older message » newer message

Bernie Ryan wrote:

> DWORD GetEnvironmentVariable(
>   LPCTSTR lpName,  // address of environment variable name
>   LPTSTR lpBuffer, // address of buffer for variable value
>   DWORD nSize      // size of buffer, in characters
> );

Please note that this Windows API function does NOT find environment symbols
that have no value because such symbols will not exist. In such case the return
value is zero.


The corresponding function ...

BOOL WINAPI SetEnvironmentVariable(
  LPCTSTR lpName,
  LPCTSTR lpValue
);

does not set/create the symbol if lName is NULL, or points to a null, or points
to a string that contains an '=' character.

Also, if lpValue is NULL or points to a null, it deletes the symbol if it
existed.

The symbols are stored in RAM using the format ...

 Var1=Value1\0
 Var2=Value2\0
 Var3=Value3\0
 ...
 VarN=ValueN\0\0

But Windows and DOS never has an entry in the form ...

  VarX=\0

So, I'm inclined to let the current functionality of getvar() remain unchanged.
If someone is actually relying on testing for the existance of a symbol
regardless of its value then either that code needs to be wrapped in an 'ifdef'
block or only run on *nix platforms. However, I suspect that this will be a very
rare requirement so I think the risk is acceptable. There is no need to
homogenize the function.

-- 
Derek Parnell
Melbourne, Australia
Skype name: derek.j.parnell

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu