changed the interface of SetEnvironmentVariableEBA
authorMartin Haimberger <martin.haimberger@gmail.com>
Wed, 23 Oct 2013 10:43:06 +0000 (03:43 -0700)
committerMartin Haimberger <martin.haimberger@gmail.com>
Wed, 23 Oct 2013 10:43:06 +0000 (03:43 -0700)
winpr/include/winpr/environment.h
winpr/libwinpr/environment/environment.c
winpr/libwinpr/environment/test/TestEnvironmentGetSetEB.c

index ba356be..3e99db7 100644 (file)
@@ -76,7 +76,7 @@ WINPR_API BOOL FreeEnvironmentStringsW(LPWCH lpszEnvironmentBlock);
 WINPR_API LPCH MergeEnvironmentStrings(PCSTR original, PCSTR merge);
 
 WINPR_API DWORD GetEnvironmentVariableEBA(LPCSTR envBlock, LPCSTR lpName, LPSTR lpBuffer, DWORD nSize);
-WINPR_API BOOL SetEnvironmentVariableEBA(LPCSTR envBlock,LPCSTR lpName, LPCSTR lpValue, LPSTR * newEnvBlock);
+WINPR_API BOOL SetEnvironmentVariableEBA(LPSTR * envBlock,LPCSTR lpName, LPCSTR lpValue);
 
 #ifdef __cplusplus
 }
index 519e1c1..62b8833 100644 (file)
@@ -232,12 +232,13 @@ BOOL SetEnvironmentVariableA(LPCSTR lpName, LPCSTR lpValue)
        return TRUE;
 }
 
-BOOL SetEnvironmentVariableEBA(LPCSTR envBlock,LPCSTR lpName, LPCSTR lpValue, LPSTR * newEnvBlock)
+BOOL SetEnvironmentVariableEBA(LPSTR * envBlock,LPCSTR lpName, LPCSTR lpValue)
 {
        int length;
        char* envstr;
        char* newEB;
 
+
        if (!lpName)
                return FALSE;
 
@@ -249,9 +250,11 @@ BOOL SetEnvironmentVariableEBA(LPCSTR envBlock,LPCSTR lpName, LPCSTR lpValue, LP
                sprintf_s(envstr, length + 1, "%s=%s", lpName, lpValue);
                envstr[length] = '\0';
 
-               newEB = MergeEnvironmentStrings(envBlock,envstr);
+               newEB = MergeEnvironmentStrings((LPCSTR)*envBlock,envstr);
                free(envstr);
-               *newEnvBlock = newEB;
+               if (*envBlock != NULL)
+                       free(*envBlock);
+               *envBlock = newEB;
                return TRUE;
        }
        else
@@ -261,9 +264,11 @@ BOOL SetEnvironmentVariableEBA(LPCSTR envBlock,LPCSTR lpName, LPCSTR lpValue, LP
                sprintf_s(envstr, length + 1, "%s=", lpName);
                envstr[length] = '\0';
 
-               newEB = MergeEnvironmentStrings(envBlock,envstr);
+               newEB = MergeEnvironmentStrings((LPCSTR)*envBlock,envstr);
                free(envstr);
-               *newEnvBlock = newEB;
+               if (*envBlock != NULL)
+                       free(*envBlock);
+               *envBlock = newEB;
                return TRUE;
        }
 }
index de5f73f..0420e88 100644 (file)
@@ -27,7 +27,10 @@ int TestEnvironmentGetSetEB(int argc, char* argv[])
 
        free(p);
 
-       if (SetEnvironmentVariableEBA(lpszEnvironmentBlock,"test","5",&lpszEnvironmentBlockNew) ) {
+       lpszEnvironmentBlockNew = (LPTCH)malloc(1024);
+       memcpy(lpszEnvironmentBlockNew,lpszEnvironmentBlock,56);
+
+       if (SetEnvironmentVariableEBA(&lpszEnvironmentBlockNew,"test","5") ) {
 
                if (GetEnvironmentVariableEBA(lpszEnvironmentBlockNew,"test", test, 1023) ) {
                        if (strcmp(test,"5") != 0) {
@@ -38,9 +41,9 @@ int TestEnvironmentGetSetEB(int argc, char* argv[])
                }
        }
 
-       free(lpszEnvironmentBlockNew);
+       //free(lpszEnvironmentBlockNew);
 
-       if (SetEnvironmentVariableEBA(lpszEnvironmentBlock,"test",NULL,&lpszEnvironmentBlockNew) ) {
+       if (SetEnvironmentVariableEBA(&lpszEnvironmentBlockNew,"test",NULL) ) {
 
                if (GetEnvironmentVariableEBA(lpszEnvironmentBlockNew,"test", test, 1023) ) {
                        return -1;