Check return value of XGetWindowProperty in x11_get_address
[platform/upstream/dbus.git] / dbus / dbus-spawn-win.c
index 1365b2c..8ac837e 100644 (file)
@@ -9,9 +9,6 @@
 #endif
 
 #include <stdio.h>
-#ifdef DBUS_WINCE
-#include <process.h>
-#endif
 
 /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
 /* dbus-spawn-win32.c Wrapper around g_spawn
@@ -53,7 +50,9 @@
 
 #include <stdlib.h>
 
+#ifndef DBUS_WINCE
 #include <process.h>
+#endif
 
 /**
  * Babysitter implementation details
@@ -472,7 +471,7 @@ protect_argv (char  **argv,
 
 /* From GPGME, relicensed by g10 Code GmbH.  */
 static char *
-build_commandline (char **argv)
+compose_string (char **strings, char separator)
 {
   int i;
   int n = 0;
@@ -480,44 +479,73 @@ build_commandline (char **argv)
   char *p;
   const char *ptr;
   
-  for (i = 0; argv[i]; i++)
-    n += strlen (argv[i]) + 1;
+  if (!strings || !strings[0])
+    return 0;
+  for (i = 0; strings[i]; i++)
+    n += strlen (strings[i]) + 1;
   n++;
 
   buf = p = malloc (n);
   if (!buf)
     return NULL;
-  for (i = 0; argv[i]; i++)
+  for (i = 0; strings[i]; i++)
     {
-      strcpy (p, argv[i]);
-      p += strlen (argv[i]);
-      *(p++) = ' ';
+      strcpy (p, strings[i]);
+      p += strlen (strings[i]);
+      *(p++) = separator;
     }
-  if (i)
-    p--;
+  p--;
+  *(p++) = '\0';
   *p = '\0';
 
   return buf;
 }
 
+static char *
+build_commandline (char **argv)
+{
+  return compose_string (argv, ' ');
+}
+
+static char *
+build_env_string (char** envp)
+{
+  return compose_string (envp, '\0');
+}
 
 static HANDLE
-spawn_program (const char* name, char** argv, char** envp)
+spawn_program (char* name, char** argv, char** envp)
 {
   PROCESS_INFORMATION pi = { NULL, 0, 0, 0 };
   STARTUPINFOA si;
-  char *arg_string;
+  char *arg_string, *env_string;
   BOOL result;
 
+#ifdef DBUS_WINCE
+  if (argv && argv[0])
+    arg_string = build_commandline (argv + 1);
+  else
+    arg_string = NULL;
+#else
   arg_string = build_commandline (argv);
+#endif
   if (!arg_string)
     return INVALID_HANDLE_VALUE;
 
+  env_string = build_env_string(envp);
+
   memset (&si, 0, sizeof (si));
   si.cb = sizeof (si);
+#ifdef DBUS_WINCE
   result = CreateProcessA (name, arg_string, NULL, NULL, FALSE, 0,
-                          envp, NULL, &si, &pi);
+#else
+  result = CreateProcessA (NULL, arg_string, NULL, NULL, FALSE, 0,
+#endif
+                          (LPVOID)env_string, NULL, &si, &pi);
   free (arg_string);
+  if (env_string)
+    free (env_string);
+
   if (!result)
     return INVALID_HANDLE_VALUE;