winpr API: add EnvironmentBlockToEnvpA
authorBernhard Miklautz <bernhard.miklautz@thincast.com>
Fri, 23 Oct 2015 16:17:14 +0000 (18:17 +0200)
committerBernhard Miklautz <bernhard.miklautz@thincast.com>
Fri, 23 Oct 2015 16:38:42 +0000 (18:38 +0200)
* expose EnvironmentBlockToEnvpA
* cleanup includes in process.c
* removed unused "flag" variable in _CreateProcessExA
* make ProcessHandleCloseHandle static

winpr/include/winpr/environment.h
winpr/libwinpr/environment/environment.c
winpr/libwinpr/thread/process.c

index d6329d8..34d9fb0 100644 (file)
@@ -110,6 +110,8 @@ WINPR_API LPCH MergeEnvironmentStrings(PCSTR original, PCSTR merge);
 WINPR_API DWORD GetEnvironmentVariableEBA(LPCSTR envBlock, LPCSTR lpName, LPSTR lpBuffer, DWORD nSize);
 WINPR_API BOOL SetEnvironmentVariableEBA(LPSTR* envBlock, LPCSTR lpName, LPCSTR lpValue);
 
 WINPR_API DWORD GetEnvironmentVariableEBA(LPCSTR envBlock, LPCSTR lpName, LPSTR lpBuffer, DWORD nSize);
 WINPR_API BOOL SetEnvironmentVariableEBA(LPSTR* envBlock, LPCSTR lpName, LPCSTR lpValue);
 
+WINPR_API char** EnvironmentBlockToEnvpA(LPCH lpszEnvironmentBlock);
+
 #ifdef __cplusplus
 }
 #endif
 #ifdef __cplusplus
 }
 #endif
index dcdb24f..58abed8 100644 (file)
@@ -572,3 +572,52 @@ BOOL SetEnvironmentVariableEBA(LPSTR* envBlock, LPCSTR lpName, LPCSTR lpValue)
 
        return TRUE;
 }
 
        return TRUE;
 }
+
+char** EnvironmentBlockToEnvpA(LPCH lpszEnvironmentBlock)
+{
+       char* p;
+       int index;
+       int count;
+       int length;
+       char** envp = NULL;
+
+       count = 0;
+       if (!lpszEnvironmentBlock)
+               return NULL;
+
+       p = (char*) lpszEnvironmentBlock;
+
+       while (p[0] && p[1])
+       {
+               length = strlen(p);
+               p += (length + 1);
+               count++;
+       }
+
+       index = 0;
+       p = (char*) lpszEnvironmentBlock;
+
+       envp = (char**) calloc(count + 1, sizeof(char*));
+       if (!envp)
+               return NULL;
+       envp[count] = NULL;
+
+       while (p[0] && p[1])
+       {
+               length = strlen(p);
+               envp[index] = _strdup(p);
+               if (!envp[index])
+               {
+                       for (index -= 1; index >= 0; --index)
+                       {
+                               free(envp[index]);
+                       }
+                       free(envp);
+                       return NULL;
+               }
+               p += (length + 1);
+               index++;
+       }
+
+       return envp;
+}
index 52aac77..2c179c7 100644 (file)
@@ -26,7 +26,6 @@
 #include "../handle/nonehandle.h"
 
 #include <winpr/thread.h>
 #include "../handle/nonehandle.h"
 
 #include <winpr/thread.h>
-#include <fcntl.h>
 
 /**
  * CreateProcessA
 
 /**
  * CreateProcessA
 
 #ifndef _WIN32
 
 
 #ifndef _WIN32
 
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif
-
 #include <winpr/crt.h>
 #include <winpr/crt.h>
-#include <winpr/heap.h>
 #include <winpr/path.h>
 #include <winpr/path.h>
-#include <winpr/tchar.h>
 #include <winpr/environment.h>
 
 #include <winpr/environment.h>
 
-#include <pwd.h>
 #include <grp.h>
 
 #include <grp.h>
 
-#include <errno.h>
-#include <string.h>
 #include <signal.h>
 #include <signal.h>
-#include <sys/wait.h>
-#include <sys/types.h>
-
-#include <pthread.h>
 
 #include "thread.h"
 
 
 #include "thread.h"
 
-#include "../handle/handle.h"
 #include "../security/security.h"
 
 #ifndef NSIG
 #include "../security/security.h"
 
 #ifndef NSIG
 #endif
 #endif
 
 #endif
 #endif
 
-char** EnvironmentBlockToEnvpA(LPCH lpszEnvironmentBlock)
-{
-       char* p;
-       int index;
-       int count;
-       int length;
-       char** envp = NULL;
-
-       count = 0;
-       if (!lpszEnvironmentBlock)
-               return NULL;
-
-       p = (char*) lpszEnvironmentBlock;
-
-       while (p[0] && p[1])
-       {
-               length = strlen(p);
-               p += (length + 1);
-               count++;
-       }
-
-       index = 0;
-       p = (char*) lpszEnvironmentBlock;
-
-       envp = (char**) calloc(count + 1, sizeof(char*));
-       if (!envp)
-               return NULL;
-       envp[count] = NULL;
-
-       while (p[0] && p[1])
-       {
-               length = strlen(p);
-               envp[index] = _strdup(p);
-               if (!envp[index])
-               {
-                       for (index -= 1; index >= 0; --index)
-                       {
-                               free(envp[index]);
-                       }
-                       free(envp);
-                       return NULL;
-               }
-               p += (length + 1);
-               index++;
-       }
-
-       return envp;
-}
-
 /**
  * If the file name does not contain a directory path, the system searches for the executable file in the following sequence:
  *
 /**
  * If the file name does not contain a directory path, the system searches for the executable file in the following sequence:
  *
@@ -151,7 +87,7 @@ char** EnvironmentBlockToEnvpA(LPCH lpszEnvironmentBlock)
  *    this per-application path in the search sequence, use the ShellExecute function.
  */
 
  *    this per-application path in the search sequence, use the ShellExecute function.
  */
 
-char* FindApplicationPath(char* application)
+static char* FindApplicationPath(char* application)
 {
        char* path;
        char* save;
 {
        char* path;
        char* save;
@@ -208,7 +144,6 @@ BOOL _CreateProcessExA(HANDLE hToken, DWORD dwLogonFlags,
                LPCSTR lpCurrentDirectory, LPSTARTUPINFOA lpStartupInfo, LPPROCESS_INFORMATION lpProcessInformation)
 {
        pid_t pid;
                LPCSTR lpCurrentDirectory, LPSTARTUPINFOA lpStartupInfo, LPPROCESS_INFORMATION lpProcessInformation)
 {
        pid_t pid;
-       int flags;
        int numArgs;
        LPSTR* pArgs = NULL;
        char** envp = NULL;
        int numArgs;
        LPSTR* pArgs = NULL;
        char** envp = NULL;
@@ -230,7 +165,6 @@ BOOL _CreateProcessExA(HANDLE hToken, DWORD dwLogonFlags,
        if (!pArgs)
                return FALSE;
 
        if (!pArgs)
                return FALSE;
 
-       flags = 0;
 
        token = (WINPR_ACCESS_TOKEN*) hToken;
 
 
        token = (WINPR_ACCESS_TOKEN*) hToken;
 
@@ -532,7 +466,7 @@ BOOL TerminateProcess(HANDLE hProcess, UINT uExitCode)
 }
 
 
 }
 
 
-BOOL ProcessHandleCloseHandle(HANDLE handle)
+static BOOL ProcessHandleCloseHandle(HANDLE handle)
 {
        WINPR_PROCESS* process = (WINPR_PROCESS*) handle;
        free(process);
 {
        WINPR_PROCESS* process = (WINPR_PROCESS*) handle;
        free(process);
@@ -586,6 +520,5 @@ HANDLE CreateProcessHandle(pid_t pid)
        return (HANDLE)process;
 }
 
        return (HANDLE)process;
 }
 
-
 #endif
 
 #endif