putenv should return success on deletion of nonexistent variable.
[reactos.git] / reactos / lib / crt / misc / environ.c
index 7847d2a..02f8345 100644 (file)
@@ -5,20 +5,20 @@
  * ReactOS MSVCRT.DLL Compatibility Library
  */
 
-#include "precomp.h"
-#include <msvcrt/internal/tls.h>
-#include <msvcrt/stdlib.h>
-#include <msvcrt/string.h>
-  
+#include <precomp.h>
+#include <internal/tls.h>
+#include <stdlib.h>
+#include <string.h>
+
 #define NDEBUG
-#include <msvcrt/msvcrtdbg.h>
+#include <internal/debug.h>
 
 
 unsigned int _osver = 0;
 unsigned int _winminor = 0;
 unsigned int _winmajor = 0;
 unsigned int _winver = 0;
+
 
 char *_acmdln = NULL;        /* pointer to ascii command line */
 wchar_t *_wcmdln = NULL;     /* pointer to wide character command line */
@@ -28,8 +28,10 @@ char **_environ = NULL;      /* pointer to environment block */
 wchar_t **_wenviron = NULL;  /* pointer to environment block */
 char **__initenv = NULL;     /* pointer to initial environment block */
 wchar_t **__winitenv = NULL; /* pointer to initial environment block */
-#undef _pgmptr 
+#undef _pgmptr
 char *_pgmptr = NULL;        /* pointer to program name */
+#undef _wpgmptr
+wchar_t *_wpgmptr = NULL;    /* pointer to program name */
 int __app_type = 0; //_UNKNOWN_APP; /* application type */
 int __mb_cur_max = 1;
 
@@ -82,7 +84,7 @@ int BlockEnvToEnvironA(void)
       /* Add terminating NULL entry. */
       *envptr = NULL;
    }
-    
+
    FreeEnvironmentStringsA(environment_strings);
    return _environ ? 0 : -1;
 }
@@ -133,7 +135,7 @@ int BlockEnvToEnvironW(void)
       /* Add terminating NULL entry. */
       *envptr = NULL;
    }
-    
+
    FreeEnvironmentStringsW(environment_strings);
    return _wenviron ? 0 : -1;
 }
@@ -175,8 +177,9 @@ char **DuplicateEnvironment(char **original_environment, int wide)
             free(*newenvptr);
          free(newenv);
          return original_environment;
-      }      
-   }   
+      }
+   }
+   *newenvptr = NULL;
 
    return newenv;
 }
@@ -256,7 +259,7 @@ int SetEnv(const wchar_t *option)
       if (!found)
       {
          free(name);
-         return -1;
+         return 0;
       }
 
       /* Remove the option from wide character environment. */
@@ -269,8 +272,7 @@ int SetEnv(const wchar_t *option)
        * the environments are in sync and the option is at the
        * same position. */
       free(_environ[index]);
-      for (; _environ[index] != NULL; index++)
-         _environ[index] = _environ[index + 1];
+      memmove(&_environ[index], &_environ[index+1], (count - index) * sizeof(char*));
       _environ = realloc(_environ, count * sizeof(char*));
 
       result = SetEnvironmentVariableW(name, NULL) ? 0 : -1;
@@ -370,6 +372,14 @@ char **__p__acmdln(void)
     return &_acmdln;
 }
 
+/*
+ * @implemented
+ */
+wchar_t **__p__wcmdln(void)
+{
+    return &_wcmdln;
+}
+
 /*
  * @implemented
  */
@@ -426,6 +436,14 @@ char **__p__pgmptr(void)
     return &_pgmptr;
 }
 
+/*
+ * @implemented
+ */
+wchar_t **__p__wpgmptr(void)
+{
+    return &_wpgmptr;
+}
+
 /*
  * @implemented
  */