Re: [ID 19991001.005] [_61] [PATCH] tarball fine on win32, zip isn't
[p5sagit/p5-mst-13.2.git] / win32 / win32.c
index a011573..1d61eb7 100644 (file)
 int _CRT_glob = 0;
 #endif
 
+#ifdef __BORLANDC__
+#  define _stat stat
+#  define _utimbuf utimbuf
+#endif
+
 #define EXECF_EXEC 1
 #define EXECF_SPAWN 2
 #define EXECF_SPAWN_NOWAIT 3
@@ -1551,9 +1556,9 @@ extern char *     des_fcrypt(const char *txt, const char *salt, char *cbuf);
 DllExport char *
 win32_crypt(const char *txt, const char *salt)
 {
+    dTHXo;
 #ifdef HAVE_DES_FCRYPT
     dTHR;
-    dTHXo;
     return des_fcrypt(txt, salt, crypt_buffer);
 #else
     die("The crypt() function is unimplemented due to excessive paranoia.");
@@ -1797,12 +1802,14 @@ win32_str_os_error(void *sv, DWORD dwErr)
                          |FORMAT_MESSAGE_IGNORE_INSERTS
                          |FORMAT_MESSAGE_FROM_SYSTEM, NULL,
                           dwErr, 0, (char *)&sMsg, 1, NULL);
+    /* strip trailing whitespace and period */
     if (0 < dwLen) {
-       while (0 < dwLen  &&  isSPACE(sMsg[--dwLen]))
-           ;
+       do {
+           --dwLen;    /* dwLen doesn't include trailing null */
+       } while (0 < dwLen && isSPACE(sMsg[dwLen]));
        if ('.' != sMsg[dwLen])
            dwLen++;
-       sMsg[dwLen]= '\0';
+       sMsg[dwLen] = '\0';
     }
     if (0 == dwLen) {
        sMsg = (char*)LocalAlloc(0, 64/**sizeof(TCHAR)*/);
@@ -2468,6 +2475,35 @@ GIVE_UP:
     return Nullch;
 }
 
+/* The following are just place holders.
+ * Some hosts may provide and environment that the OS is
+ * not tracking, therefore, these host must provide that
+ * environment and the current directory to CreateProcess
+ */
+
+void*
+get_childenv(void)
+{
+    return NULL;
+}
+
+void
+free_childenv(void* d)
+{
+}
+
+char*
+get_childdir(void)
+{
+    return NULL;
+}
+
+void
+free_childdir(char* d)
+{
+}
+
+
 /* XXX this needs to be made more compatible with the spawnvp()
  * provided by the various RTLs.  In particular, searching for
  * *.{com,bat,cmd} files (as done by the RTLs) is unimplemented.
@@ -2487,6 +2523,8 @@ win32_spawnvp(int mode, const char *cmdname, const char *const *argv)
 #else
     dTHXo;
     DWORD ret;
+    void* env;
+    char* dir;
     STARTUPINFO StartupInfo;
     PROCESS_INFORMATION ProcessInformation;
     DWORD create = 0;
@@ -2495,6 +2533,9 @@ win32_spawnvp(int mode, const char *cmdname, const char *const *argv)
                                             ? &argv[1] : argv);
     char *fullcmd = Nullch;
 
+    env = PerlEnv_get_childenv();
+    dir = PerlEnv_get_childdir();
+
     switch(mode) {
     case P_NOWAIT:     /* asynch + remember result */
        if (w32_num_children >= MAXIMUM_WAIT_OBJECTS) {
@@ -2525,11 +2566,6 @@ win32_spawnvp(int mode, const char *cmdname, const char *const *argv)
        create |= CREATE_NEW_CONSOLE;
     }
 
-#ifndef DEBUGGING
-    StartupInfo.dwFlags |= STARTF_USESHOWWINDOW;
-    StartupInfo.wShowWindow = SW_HIDE;
-#endif
-
 RETRY:
     if (!CreateProcess(cmdname,                /* search PATH to find executable */
                       cmd,             /* executable, and its arguments */
@@ -2537,8 +2573,8 @@ RETRY:
                       NULL,            /* thread attributes */
                       TRUE,            /* inherit handles */
                       create,          /* creation flags */
-                      NULL,            /* inherit environment */
-                      NULL,            /* inherit cwd */
+                      (LPVOID)env,     /* inherit environment */
+                      dir,             /* inherit cwd */
                       &StartupInfo,
                       &ProcessInformation))
     {
@@ -2573,7 +2609,10 @@ RETRY:
     }
 
     CloseHandle(ProcessInformation.hThread);
+
 RETVAL:
+    PerlEnv_free_childenv(env);
+    PerlEnv_free_childdir(dir);
     Safefree(cmd);
     Safefree(fullcmd);
     return (int)ret;