3f5c3de00d8195c3ea4778907e5333bfbd3ce613
[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 int _putenv(const char* val)
12 {
13     char* buffer;
14     char* epos;
15     int res;
16
17     DPRINT("_putenv('%s')\n", val);
18     epos = strchr(val, '=');
19     if ( epos == NULL )
20         return -1;
21     buffer = (char*)malloc(epos - val + 1);
22     if (buffer == NULL)
23         return -1;
24     strncpy(buffer, val, epos - val);
25     buffer[epos - val] = 0;
26     res = SetEnvironmentVariableA(buffer, epos+1);
27     free(buffer);
28     if (BlockEnvToEnviron())
29         return 0;
30     return res;
31 }