]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/win32/compat/compat.cpp
This commit was manufactured by cvs2svn to create tag
[bacula/bacula] / bacula / src / win32 / compat / compat.cpp
index 89392cb728670113d625d4c1ec7f8923c06a7fed..80a77f578d8152f78a349974c01b3064d599c5dd 100644 (file)
@@ -36,7 +36,7 @@
 extern void d_msg(const char *file, int line, int level, const char *fmt,...);
 extern DWORD   g_platform_id;
 
-// from CYGWIN (should be diff between Jan 1 1601 and Jan 1 1970
+// from MicroSoft SDK (KES) is the diff between Jan 1 1601 and Jan 1 1970
 #ifdef HAVE_MINGW
 #define WIN32_FILETIME_ADJUST 0x19DB1DED53E8000UL //Not sure it works
 #else
@@ -452,7 +452,7 @@ strncasecmp(const char *s1, const char *s2, int len)
         ch2 = *s2;
         s1++;
         s2++;
-       if (ch1 == 0 || tolower(ch1) != tolower(ch2)) break;
+        if (ch1 == 0 || tolower(ch1) != tolower(ch2)) break;
     } 
 
     return(ch1 - ch2);
@@ -794,14 +794,14 @@ getArgv0(const char *cmdline)
     int inquote = 0;
     for (const char *cp = cmdline; *cp; cp++)
     {
-       if (*cp == '"') {
-           inquote = !inquote;
-       }
-       if (!inquote && isspace(*cp))
-           break;
+        if (*cp == '"') {
+            inquote = !inquote;
+        }
+        if (!inquote && isspace(*cp))
+            break;
     }
 
-       
+        
     int len = cp - cmdline;
     char *rval = (char *)malloc(len+1);
 
@@ -815,20 +815,6 @@ getArgv0(const char *cmdline)
     return rval;
 }
 
-/*
- * Check to see if filename has the batch file extention.
- */
-int
-isBatchFile(const char *fname)
-{
-    const char *ext = strrchr(fname, '.');
-    
-    if (ext) {
-       int rval = strncasecmp(ext, ".bat", 4);
-       return !rval;
-    }
-    return 0;
-}
 
 /**
  * OK, so it would seem CreateProcess only handles true executables:
@@ -871,55 +857,20 @@ CreateChildProcess(const char *cmdline, HANDLE in, HANDLE out, HANDLE err)
         siStartInfo.hStdError = GetStdHandle(STD_ERROR_HANDLE);
     // Create the child process.
 
-    char cmdLine[1024];
-    char exeFile[1024];
-    // retrive the first compont of the command line which should be the
-    // executable
-    const char *exeName = getArgv0(cmdline);
-
-    if (isBatchFile(exeName)) {
-       const char *comspec = getenv("COMSPEC");
-       if (comspec == NULL) // should never happen
-           return INVALID_HANDLE_VALUE;
-
-       free((void *)exeName);
-       strcpy(exeFile, comspec);
-       strcpy(cmdLine, comspec);
-       strcat(cmdLine, " /c ");
-       strcat(cmdLine, cmdline);
-    }
-    else
-    {
-    // check to see if absolute path was passed to us already?
-       // allow for case when absolute path is in quotes "C:/...."
-       int driveCheck = exeName[0] == '"' ? 2 : 1;
-       if (exeName[driveCheck] != ':'
-           || (strchr(cmdline, '/') == NULL
-               && strchr(cmdline, '\\') == NULL))
-       {
-           // only command name so perform search of PATH to find
-           char *file;
-           DWORD rval = SearchPath(NULL,
-                                   exeName,
-                                   ".exe",
-                                   sizeof(exeFile),
-                                   exeFile,
-                                   &file);
-           if (rval == 0)
-               return INVALID_HANDLE_VALUE;
-           if (rval > sizeof(exeFile))
-               return INVALID_HANDLE_VALUE;
-           
-       }
-       else
-           cygwin_conv_to_win32_path(exeName, exeFile);
-       
-       // exeFile now has absolute path to program to execute.
-       free((void *)exeName);
-
-       // copy original command line to pass to create process
-       strcpy(cmdLine, cmdline);
-    }
+    char exeFile[256];
+
+    const char *comspec = getenv("COMSPEC");
+    
+    if (comspec == NULL) // should never happen
+        return INVALID_HANDLE_VALUE;
+
+    char *cmdLine = (char *)alloca(strlen(cmdline) + strlen(comspec) + 16);
+    
+    strcpy(exeFile, comspec);
+    strcpy(cmdLine, comspec);
+    strcat(cmdLine, " /c ");
+    strcat(cmdLine, cmdline);
+
     // try to execute program
     bFuncRetn = CreateProcess(exeFile,
                               cmdLine, // command line
@@ -1022,7 +973,7 @@ open_bpipe(char *prog, int wait, const char *mode)
         }
 
         CloseHandle(hChildStdoutRd);
-       hChildStdoutRd = INVALID_HANDLE_VALUE;
+        hChildStdoutRd = INVALID_HANDLE_VALUE;
     }
 
     if (mode_write) {
@@ -1046,7 +997,7 @@ open_bpipe(char *prog, int wait, const char *mode)
         }
 
         CloseHandle(hChildStdinWr);
-       hChildStdinWr = INVALID_HANDLE_VALUE;
+        hChildStdinWr = INVALID_HANDLE_VALUE;
     }
     // spawn program with redirected handles as appropriate
     bpipe->worker_pid = (pid_t)
@@ -1211,7 +1162,10 @@ open(const char *file, int flags, int mode)
 int
 close(int fd)
 {
-    return _close(fd);
+    int rval = _close(fd);
+    if (rval == -1)
+        rval = closesocket(fd);
+    return rval;
 }
 
 #ifndef HAVE_WXCONSOLE