2 * msvcrt.dll environment functions
4 * Copyright 1996,1998 Marcus Meissner
5 * Copyright 1996 Jukka Iivonen
6 * Copyright 1997,2000 Uwe Bonnes
7 * Copyright 2000 Jon Griffiths
9 #include "wine/unicode.h"
12 #include "msvcrt/stdlib.h"
15 DEFAULT_DEBUG_CHANNEL(msvcrt);
17 /*********************************************************************
20 char *MSVCRT_getenv(const char *name)
22 char *environ = GetEnvironmentStringsA();
24 unsigned int length=strlen(name);
26 for (pp = environ; (*pp); pp = pp + strlen(pp) +1)
29 if ((pos) && ((pos - pp) == length))
31 if (!strncasecmp(pp,name,length)) break;
41 FreeEnvironmentStringsA( environ );
45 /*********************************************************************
48 WCHAR *_wgetenv(const WCHAR *name)
50 WCHAR* environ = GetEnvironmentStringsW();
51 WCHAR* pp,*pos = NULL;
52 unsigned int length=strlenW(name);
54 for (pp = environ; (*pp); pp = pp + strlenW(pp) + 1)
56 pos = strchrW(pp,'=');
57 if ((pos) && ((pos - pp) == length))
59 if (!strncmpiW(pp,name,length))
62 TRACE("got %s\n",debugstr_w(pp));
63 /* can't free pointer since we are returning it */
64 /* should probably use MSVCRT_wenviron instead */
65 FIXME( "memory leak\n" );
70 FreeEnvironmentStringsW( environ );
74 /*********************************************************************
77 int _putenv(const char *str)
79 char name[256], value[512];
86 while (*str && *str != '=')
96 return !SetEnvironmentVariableA(name, value[0] ? value : NULL);
99 /*********************************************************************
100 * _wputenv (MSVCRT.@)
102 int _wputenv(const WCHAR *str)
104 WCHAR name[256], value[512];
107 TRACE("%s\n", debugstr_w(str));
111 while (*str && *str != (WCHAR)L'=')
121 return !SetEnvironmentVariableW(name, value[0] ? value : NULL);