update for HEAD-2003091401
[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 /*
12  * @implemented
13  */
14 int _wputenv(const wchar_t* val)
15 {
16     wchar_t* buffer;
17     wchar_t* epos;
18     int res;
19
20     DPRINT("_wputenv('%S')\n", val);
21     epos = wcsrchr(val, L'=');
22     if (epos == NULL)
23         return -1;
24     buffer = (wchar_t*)malloc((epos - val + 1) * sizeof(wchar_t));
25     if (buffer == NULL)
26         return -1;
27     wcsncpy(buffer, val, epos - val);
28     buffer[epos - val] = 0;
29     res = SetEnvironmentVariableW(buffer, epos+1);
30     free(buffer);
31     if (BlockEnvToEnviron())
32         return 0;
33     return  res;
34 }