2001-01-11 00:59:25 +01:00
|
|
|
/*
|
|
|
|
* msvcrt.dll environment functions
|
|
|
|
*
|
|
|
|
* Copyright 1996,1998 Marcus Meissner
|
|
|
|
* Copyright 1996 Jukka Iivonen
|
|
|
|
* Copyright 1997,2000 Uwe Bonnes
|
|
|
|
* Copyright 2000 Jon Griffiths
|
|
|
|
*/
|
|
|
|
#include "wine/unicode.h"
|
|
|
|
#include "msvcrt.h"
|
|
|
|
|
2001-04-11 01:25:25 +02:00
|
|
|
#include "msvcrt/stdlib.h"
|
|
|
|
|
2001-01-11 00:59:25 +01:00
|
|
|
|
2001-04-11 01:25:25 +02:00
|
|
|
DEFAULT_DEBUG_CHANNEL(msvcrt);
|
2001-01-11 00:59:25 +01:00
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* getenv (MSVCRT.@)
|
|
|
|
*/
|
2001-04-10 23:16:07 +02:00
|
|
|
char *MSVCRT_getenv(const char *name)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
2001-01-22 03:21:54 +01:00
|
|
|
char *environ = GetEnvironmentStringsA();
|
|
|
|
char *pp,*pos = NULL;
|
2001-11-23 19:30:19 +01:00
|
|
|
unsigned int length=strlen(name);
|
2001-01-11 00:59:25 +01:00
|
|
|
|
|
|
|
for (pp = environ; (*pp); pp = pp + strlen(pp) +1)
|
|
|
|
{
|
2001-11-23 19:30:19 +01:00
|
|
|
pos =strchr(pp,'=');
|
|
|
|
if ((pos) && ((pos - pp) == length))
|
|
|
|
{
|
2001-12-05 23:09:00 +01:00
|
|
|
if (!strncasecmp(pp,name,length)) break;
|
2001-11-23 19:30:19 +01:00
|
|
|
}
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
2001-11-23 19:30:19 +01:00
|
|
|
if ((*pp)&& (pos))
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
|
|
|
pp = pos+1;
|
|
|
|
TRACE("got %s\n",pp);
|
|
|
|
}
|
2001-11-23 19:30:19 +01:00
|
|
|
else
|
|
|
|
pp = 0;
|
2001-01-11 00:59:25 +01:00
|
|
|
FreeEnvironmentStringsA( environ );
|
|
|
|
return pp;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _wgetenv (MSVCRT.@)
|
|
|
|
*/
|
2001-04-10 23:16:07 +02:00
|
|
|
WCHAR *_wgetenv(const WCHAR *name)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
|
|
|
WCHAR* environ = GetEnvironmentStringsW();
|
|
|
|
WCHAR* pp,*pos = NULL;
|
2001-11-23 19:30:19 +01:00
|
|
|
unsigned int length=strlenW(name);
|
2001-01-11 00:59:25 +01:00
|
|
|
|
|
|
|
for (pp = environ; (*pp); pp = pp + strlenW(pp) + 1)
|
|
|
|
{
|
2001-11-23 19:30:19 +01:00
|
|
|
pos = strchrW(pp,'=');
|
|
|
|
if ((pos) && ((pos - pp) == length))
|
|
|
|
{
|
2001-12-05 23:09:00 +01:00
|
|
|
if (!strncmpiW(pp,name,length))
|
2001-11-23 19:30:19 +01:00
|
|
|
{
|
|
|
|
pp = pos+1;
|
|
|
|
TRACE("got %s\n",debugstr_w(pp));
|
|
|
|
/* can't free pointer since we are returning it */
|
|
|
|
/* should probably use MSVCRT_wenviron instead */
|
|
|
|
FIXME( "memory leak\n" );
|
|
|
|
return pp;
|
|
|
|
}
|
|
|
|
}
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
|
|
|
FreeEnvironmentStringsW( environ );
|
2001-11-23 19:30:19 +01:00
|
|
|
return NULL;
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
2001-01-22 03:21:54 +01:00
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _putenv (MSVCRT.@)
|
|
|
|
*/
|
2001-04-10 23:16:07 +02:00
|
|
|
int _putenv(const char *str)
|
2001-01-22 03:21:54 +01:00
|
|
|
{
|
|
|
|
char name[256], value[512];
|
|
|
|
char *dst = name;
|
|
|
|
|
|
|
|
TRACE("%s\n", str);
|
|
|
|
|
|
|
|
if (!str)
|
|
|
|
return -1;
|
|
|
|
while (*str && *str != '=')
|
|
|
|
*dst++ = *str++;
|
|
|
|
if (!*str++)
|
|
|
|
return -1;
|
|
|
|
*dst = '\0';
|
|
|
|
dst = value;
|
|
|
|
while (*str)
|
|
|
|
*dst++ = *str++;
|
|
|
|
*dst = '\0';
|
|
|
|
|
|
|
|
return !SetEnvironmentVariableA(name, value[0] ? value : NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _wputenv (MSVCRT.@)
|
|
|
|
*/
|
2001-04-10 23:16:07 +02:00
|
|
|
int _wputenv(const WCHAR *str)
|
2001-01-22 03:21:54 +01:00
|
|
|
{
|
|
|
|
WCHAR name[256], value[512];
|
|
|
|
WCHAR *dst = name;
|
|
|
|
|
|
|
|
TRACE("%s\n", debugstr_w(str));
|
|
|
|
|
|
|
|
if (!str)
|
|
|
|
return -1;
|
|
|
|
while (*str && *str != (WCHAR)L'=')
|
|
|
|
*dst++ = *str++;
|
|
|
|
if (!*str++)
|
|
|
|
return -1;
|
|
|
|
*dst = (WCHAR)L'\0';
|
|
|
|
dst = value;
|
|
|
|
while (*str)
|
|
|
|
*dst++ = *str++;
|
|
|
|
*dst = (WCHAR)L'\0';
|
|
|
|
|
|
|
|
return !SetEnvironmentVariableW(name, value[0] ? value : NULL);
|
|
|
|
}
|