setenv in Windows + phobos and tango

Derek Parnell derek at psych.ward
Tue Mar 6 13:08:04 PST 2007


On Wed, 07 Mar 2007 05:49:00 +1100, Daniel Keep wrote:

> Unfortunetly, std.c.stdlib.setenv isn't supported
> on Windows.

I use this (and it works) ...

import std.string;
alias char[] string;
extern (C)
{
    char*   getenv  (char *);
    int     putenv  (char *);
}

//-------------------------------------------------------
string GetEnv(string pSymbol)
//-------------------------------------------------------
{
    return std.string.toString(getenv(std.string.toStringz(pSymbol)));
}

//-------------------------------------------------------
void SetEnv(string pSymbol, string pValue, bool pOverwrite = true)
//-------------------------------------------------------
{
    if (pOverwrite || GetEnv(pSymbol).length == 0)
        putenv(std.string.toStringz(pSymbol ~ "=" ~ pValue));
}

-- 
Derek Parnell
Melbourne, Australia
"Justice for David Hicks!"
skype: derek.j.parnell


More information about the Digitalmars-d-learn mailing list