]> code.delx.au - gnu-emacs/blobdiff - src/w32proc.c
Update copyright year to 2015
[gnu-emacs] / src / w32proc.c
index 96f94a116af0b0e20dd05124bf7e1fe7893d3294..0c178e7a2f63bb9f7c9ca689c9c2b17e74c8c7ae 100644 (file)
@@ -1,6 +1,6 @@
 /* Process support for GNU Emacs on the Microsoft Windows API.
 
-Copyright (C) 1992, 1995, 1999-2014 Free Software Foundation, Inc.
+Copyright (C) 1992, 1995, 1999-2015 Free Software Foundation, Inc.
 
 This file is part of GNU Emacs.
 
@@ -1078,6 +1078,7 @@ create_child (char *exe, char *cmdline, char *env, int is_gui_app,
   DWORD flags;
   char dir[ MAX_PATH ];
   char *p;
+  const char *ext;
 
   if (cp == NULL) emacs_abort ();
 
@@ -1116,6 +1117,15 @@ create_child (char *exe, char *cmdline, char *env, int is_gui_app,
     if (*p == '/')
       *p = '\\';
 
+  /* CreateProcess handles batch files as exe specially.  This special
+     handling fails when both the batch file and arguments are quoted.
+     We pass NULL as exe to avoid the special handling. */
+  if (exe && cmdline[0] == '"' &&
+      (ext = strrchr (exe, '.')) &&
+      (xstrcasecmp (ext, ".bat") == 0
+       || xstrcasecmp (ext, ".cmd") == 0))
+      exe = NULL;
+
   flags = (!NILP (Vw32_start_process_share_console)
           ? CREATE_NEW_PROCESS_GROUP
           : CREATE_NEW_CONSOLE);
@@ -1605,6 +1615,15 @@ sys_spawnve (int mode, char *cmdname, char **argv, char **envp)
       program = ENCODE_FILE (full);
       cmdname = SDATA (program);
     }
+  else
+    {
+      char *p = alloca (strlen (cmdname) + 1);
+
+      /* Don't change the command name we were passed by our caller
+        (unixtodos_filename below will destructively mirror forward
+        slashes).  */
+      cmdname = strcpy (p, cmdname);
+    }
 
   /* make sure argv[0] and cmdname are both in DOS format */
   unixtodos_filename (cmdname);
@@ -1646,10 +1665,7 @@ sys_spawnve (int mode, char *cmdname, char **argv, char **envp)
       if (egetenv ("CMDPROXY"))
        strcpy (cmdname, egetenv ("CMDPROXY"));
       else
-       {
-         strcpy (cmdname, SDATA (Vinvocation_directory));
-         strcat (cmdname, "cmdproxy.exe");
-       }
+       strcpy (lispstpcpy (cmdname, Vinvocation_directory), "cmdproxy.exe");
 
       /* Can't use unixtodos_filename here, since that needs its file
         name argument encoded in UTF-8.  */
@@ -2909,7 +2925,7 @@ int_from_hex (char * s)
    function isn't given a context pointer.  */
 Lisp_Object Vw32_valid_locale_ids;
 
-static BOOL CALLBACK
+static BOOL CALLBACK ALIGN_STACK
 enum_locale_fn (LPTSTR localeNum)
 {
   DWORD id = int_from_hex (localeNum);
@@ -2973,7 +2989,7 @@ If successful, the new locale id is returned, otherwise nil.  */)
    function isn't given a context pointer.  */
 Lisp_Object Vw32_valid_codepages;
 
-static BOOL CALLBACK
+static BOOL CALLBACK ALIGN_STACK
 enum_codepage_fn (LPTSTR codepageNum)
 {
   DWORD id = atoi (codepageNum);
@@ -3054,7 +3070,12 @@ If successful, the new CP is returned, otherwise nil.  */)
 DEFUN ("w32-get-codepage-charset", Fw32_get_codepage_charset,
        Sw32_get_codepage_charset, 1, 1, 0,
        doc: /* Return charset ID corresponding to codepage CP.
-Returns nil if the codepage is not valid.  */)
+Returns nil if the codepage is not valid or its charset ID could
+not be determined.
+
+Note that this function is only guaranteed to work with ANSI
+codepages; most console codepages are not supported and will
+yield nil.  */)
   (Lisp_Object cp)
 {
   CHARSETINFO info;
@@ -3164,18 +3185,20 @@ get_lcid_callback (LPTSTR locale_num_str)
   if (GetLocaleInfo (try_lcid, LOCALE_SABBREVLANGNAME,
                     locval, LOCALE_NAME_MAX_LENGTH))
     {
+      size_t locval_len;
+
       /* This is for when they only specify the language, as in "ENU".  */
       if (stricmp (locval, lname) == 0)
        {
          found_lcid = try_lcid;
          return FALSE;
        }
-      strcat (locval, "_");
+      locval_len = strlen (locval);
+      strcpy (locval + locval_len, "_");
       if (GetLocaleInfo (try_lcid, LOCALE_SABBREVCTRYNAME,
-                        locval + strlen (locval), LOCALE_NAME_MAX_LENGTH))
+                        locval + locval_len + 1, LOCALE_NAME_MAX_LENGTH))
        {
-         size_t locval_len = strlen (locval);
-
+         locval_len = strlen (locval);
          if (strnicmp (locval, lname, locval_len) == 0
              && (lname[locval_len] == '.'
                  || lname[locval_len] == '\0'))