Tested subprogram invocation, fixed decode_env_path.
authorEli Zaretskii <eliz@gnu.org>
Sat, 7 Dec 2013 12:00:10 +0000 (14:00 +0200)
committerEli Zaretskii <eliz@gnu.org>
Sat, 7 Dec 2013 12:00:10 +0000 (14:00 +0200)
src/emacs.c
src/w32.c
src/w32proc.c

index 3e9635f..9f41bc2 100644 (file)
@@ -36,6 +36,7 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 #ifdef WINDOWSNT
 #include <fcntl.h>
 #include <sys/socket.h>
+#include <mbstring.h>
 #include "w32.h"
 #include "w32heap.h"
 #endif
@@ -2205,8 +2206,36 @@ decode_env_path (const char *evarname, const char *defalt)
       char *path_copy;
 
 #ifdef WINDOWSNT
-      path_copy = alloca (MAX_UTF8_PATH);
-      filename_from_ansi (path, path_copy);
+      char *path_utf8, *q, *d;
+      int cnv_result;
+
+      /* Convert each element of PATH to UTF-8.  */
+      p = path_copy = alloca (strlen (path) + 1);
+      strcpy (path_copy, path);
+      d = path_utf8 = alloca (4 * strlen (path) + 1);
+      *d = '\0';
+      do {
+       q = _mbschr (p, SEPCHAR);
+       if (q)
+         *q = '\0';
+       cnv_result = filename_from_ansi (p, d);
+       if (q)
+         {
+           *q++ = SEPCHAR;
+           p = q;
+           /* If conversion of this PATH elements fails, make sure
+              destination pointer will stay put, thus effectively
+              ignoring the offending element.  */
+           if (cnv_result == 0)
+             {
+               d += strlen (d);
+               *d++ = SEPCHAR;
+             }
+         }
+       else if (cnv_result != 0 && d > path_utf8)
+         d[-1] = '\0'; /* remove last semi-colon and null-terminate PATH */
+      } while (q);
+      path_copy = path_utf8;
 #else  /* MSDOS */
       path_copy = alloca (strlen (path) + 1);
       strcpy (path_copy, path);
index 47c4f04..0f13703 100644 (file)
--- a/src/w32.c
+++ b/src/w32.c
@@ -2020,7 +2020,7 @@ normalize_filename (register char *fp, char path_sep)
 
   while (*fp)
     {
-      if (*fp == '/' || *fp == '\\')
+      if ((*fp == '/' || *fp == '\\') && *fp != path_sep)
        *fp = path_sep;
       fp++;
     }
index 76d8bb1..d2751d5 100644 (file)
@@ -1619,7 +1619,7 @@ sys_spawnve (int mode, char *cmdname, char **argv, char **envp)
       return -1;
     }
   /* From here on, CMDNAME is an ANSI-encoded string.  */
-  cmdname = cmdname_a
+  cmdname = cmdname_a;
   argv[0] = cmdname;
 
   /* Determine whether program is a 16-bit DOS executable, or a 32-bit Windows