Use regex.[ch] from msysGit's /git
[cvsps/4msysgit.git] / setenv.c
blob29cf2a7f7ffc610ac2d3b4566ac8543a93f5d612
1 /*
3 Implement setenv and friends for MinGW
5 UNIX man
6 http://www.hmug.org/man/3/setenv.php
7 MSDN SetEnvironmentVariable
8 http://msdn2.microsoft.com/en-us/library/ms686206.aspx
10 char *
11 getenv(const char *name);
13 int
14 setenv(const char *name, const char *value, int overwrite);
16 int
17 putenv(const char *string);
19 void
20 unsetenv(const char *name);
23 #include <windows.h>
25 /*char * getenv(const char *name);*/
26 int setenv(const char *name, const char *value, int overwrite);
27 /*int putenv(const char *string);*/
28 void unsetenv(const char *name);
30 /* Implementation */
32 /* inserts or resets the environment variable name in the current environment
33 list.
35 If the variable name does not exist in the list, it is inserted with the
36 given value.
38 If the variable does exist, the argument overwrite is tested;
39 if overwrite is zero, the variable is not reset,
40 otherwise it is reset to the given value.
42 return the value 0 if successful;
43 otherwise the value -1 is returned and the global variable errno is set
44 to indicate the error.
46 int setenv(const char *name, const char *value, int overwrite) {
47 /* bug: ALWAYS OVERWRITE */
48 return SetEnvironmentVariable(name, value) != 0 ? 0 /* OK */ : -1 /* FAIL */;
51 void unsetenv(const char *name) {
52 SetEnvironmentVariable(name, NULL);