update for HEAD-2003091401
[reactos.git] / lib / msvcrt / stdlib / putenv.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 _putenv(const char* val)
15 {
16     char* buffer;
17     char* epos;
18     int res;
19
20     DPRINT("_putenv('%s')\n", val);
21     epos = strchr(val, '=');
22     if ( epos == NULL )
23         return -1;
24     buffer = (char*)malloc(epos - val + 1);
25     if (buffer == NULL)
26         return -1;
27     strncpy(buffer, val, epos - val);
28     buffer[epos - val] = 0;
29     res = SetEnvironmentVariableA(buffer, epos+1);
30     free(buffer);
31     if (BlockEnvToEnviron())
32         return 0;
33     return res;
34 }