use search path
[oweals/gnunet.git] / src / util / os_priority.c
index b68e6b8fac1547ed370503d396c7f1fc776e932b..14aab8ce1c86c5b6f44e79036f57f300b0338587 100644 (file)
@@ -249,6 +249,7 @@ GNUNET_OS_start_process (struct GNUNET_DISK_PipeHandle *pipe_stdin,
 #endif
   char *fn;
   int len;
+  char path[MAX_PATH + 1];
 
   cmdlen = 0;
   va_start (ap, filename);
@@ -281,14 +282,15 @@ GNUNET_OS_start_process (struct GNUNET_DISK_PipeHandle *pipe_stdin,
       start.hStdOutput = stdout_handle;
     }
 #endif
-  len = strlen (filename);
-  if (strnicmp (filename + len - 4, ".exe", 4) == 0)
-    fn = filename;
-  else
-    GNUNET_asprintf (&fn, "%s.exe", filename);
+  if (FindExecutable(filename, NULL, path) <= 32)
+    {
+      SetErrnoFromWinError (GetLastError ());
+      GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "FindExecutable", fn);
+      return -1;
+    }
 
   if (!CreateProcess
-      (fn, cmd, NULL, NULL, FALSE, DETACHED_PROCESS, NULL, NULL, &start,
+      (path, cmd, NULL, NULL, FALSE, DETACHED_PROCESS, NULL, NULL, &start,
        &proc))
     {
       SetErrnoFromWinError (GetLastError ());