summaryrefslogtreecommitdiff
path: root/lib-src/emacsclient.c
diff options
context:
space:
mode:
authorJuanma Barranquero <lekktu@gmail.com>2006-12-15 14:53:44 +0000
committerJuanma Barranquero <lekktu@gmail.com>2006-12-15 14:53:44 +0000
commit4472aef4c3bd2a802f4381477d747d88c867ff3d (patch)
tree4e7c068819941700384c115dcc1fcc152cc2774d /lib-src/emacsclient.c
parentc6e87e896823db85f227377dfb76e2750fd5d109 (diff)
(w32_execvp): New function; wrapper for `execvp'.
(execvp) [WINDOWSNT]: Redefine to `w32_execvp'. (fail): Remove Windows-specific fix (subsumed in w32_execvp).
Diffstat (limited to 'lib-src/emacsclient.c')
-rw-r--r--lib-src/emacsclient.c40
1 files changed, 37 insertions, 3 deletions
diff --git a/lib-src/emacsclient.c b/lib-src/emacsclient.c
index f05b98ecce..429d4b5bdc 100644
--- a/lib-src/emacsclient.c
+++ b/lib-src/emacsclient.c
@@ -298,6 +298,42 @@ Report bugs to bug-gnu-emacs@gnu.org.\n", progname);
}
+#ifdef WINDOWSNT
+
+/*
+ execvp() wrapper for Windows. Quotes arguments with embedded spaces.
+
+ This is necessary due to the broken implementation of exec* routines in
+ the Microsoft libraries: they concatenate the arguments together without
+ quoting special characters, and pass the result to CreateProcess, with
+ predictably bad results. By contrast, Posix execvp passes the arguments
+ directly into the argv[] array of the child process.
+*/
+int
+w32_execvp (path, argv)
+ char *path;
+ char **argv;
+{
+ int i;
+
+ argv[0] = (char *) alternate_editor;
+
+ for (i = 0; argv[i]; i++)
+ if (strchr (argv[i], ' '))
+ {
+ char *quoted = alloca (strlen (argv[i]) + 3);
+ sprintf (quoted, "\"%s\"", argv[i]);
+ argv[i] = quoted;
+ }
+
+ return execvp (path, argv);
+}
+
+#undef execvp
+#define execvp w32_execvp
+
+#endif /* WINDOWSNT */
+
/*
Try to run a different command, or --if no alternate editor is
defined-- exit with an errorcode.
@@ -310,9 +346,7 @@ fail (argc, argv)
if (alternate_editor)
{
int i = optind - 1;
-#ifdef WINDOWSNT
- argv[i] = (char *)alternate_editor;
-#endif
+
execvp (alternate_editor, argv + i);
message (TRUE, "%s: error executing alternate editor \"%s\"\n",
progname, alternate_editor);