update for HEAD-2003021201
[reactos.git] / lib / msvcrt / stdlib / wputenv.c
1 #include <windows.h>
2 #include <msvcrt/stdlib.h>
3 #include <msvcrt/string.h>
4
5 #define NDEBUG
6 #include <msvcrt/msvcrtdbg.h>
7
8
9 extern int BlockEnvToEnviron(); // defined in misc/dllmain.c
10
11 int _wputenv(const wchar_t* val)
12 {
13     wchar_t* buffer;
14     wchar_t* epos;
15     int res;
16
17     DPRINT("_wputenv('%S')\n", val);
18     epos = wcsrchr(val, L'=');
19     if (epos == NULL)
20         return -1;
21     buffer = (char*)malloc((epos - val + 1) * sizeof(wchar_t));
22     if (buffer == NULL)
23         return -1;
24     wcsncpy(buffer, val, epos - val);
25     buffer[epos - val] = 0;
26     res = SetEnvironmentVariableW(buffer, epos+1);
27     free(buffer);
28     if (BlockEnvToEnviron())
29         return 0;
30     return  res;
31 }