comparison lib-src/emacsclient.c @ 74637:fe8bd1af34c4

(w32_execvp): New function; wrapper for `execvp'. (execvp) [WINDOWSNT]: Redefine to `w32_execvp'. (fail): Remove Windows-specific fix (subsumed in w32_execvp).
author Juanma Barranquero <lekktu@gmail.com>
date Fri, 15 Dec 2006 14:50:38 +0000
parents c6cb776ffbb7
children 4142abafc7b4
comparison
equal deleted inserted replaced
74636:f886e6f4db4d 74637:fe8bd1af34c4
296 Report bugs to bug-gnu-emacs@gnu.org.\n", progname); 296 Report bugs to bug-gnu-emacs@gnu.org.\n", progname);
297 exit (EXIT_SUCCESS); 297 exit (EXIT_SUCCESS);
298 } 298 }
299 299
300 300
301 #ifdef WINDOWSNT
302
303 /*
304 execvp() wrapper for Windows. Quotes arguments with embedded spaces.
305
306 This is necessary due to the broken implementation of exec* routines in
307 the Microsoft libraries: they concatenate the arguments together without
308 quoting special characters, and pass the result to CreateProcess, with
309 predictably bad results. By contrast, Posix execvp passes the arguments
310 directly into the argv[] array of the child process.
311 */
312 int
313 w32_execvp (path, argv)
314 char *path;
315 char **argv;
316 {
317 int i;
318
319 argv[0] = (char *) alternate_editor;
320
321 for (i = 0; argv[i]; i++)
322 if (strchr (argv[i], ' '))
323 {
324 char *quoted = alloca (strlen (argv[i]) + 3);
325 sprintf (quoted, "\"%s\"", argv[i]);
326 argv[i] = quoted;
327 }
328
329 return execvp (path, argv);
330 }
331
332 #undef execvp
333 #define execvp w32_execvp
334
335 #endif /* WINDOWSNT */
336
301 /* 337 /*
302 Try to run a different command, or --if no alternate editor is 338 Try to run a different command, or --if no alternate editor is
303 defined-- exit with an errorcode. 339 defined-- exit with an errorcode.
304 */ 340 */
305 void 341 void
308 char **argv; 344 char **argv;
309 { 345 {
310 if (alternate_editor) 346 if (alternate_editor)
311 { 347 {
312 int i = optind - 1; 348 int i = optind - 1;
313 #ifdef WINDOWSNT 349
314 argv[i] = (char *)alternate_editor;
315 #endif
316 execvp (alternate_editor, argv + i); 350 execvp (alternate_editor, argv + i);
317 message (TRUE, "%s: error executing alternate editor \"%s\"\n", 351 message (TRUE, "%s: error executing alternate editor \"%s\"\n",
318 progname, alternate_editor); 352 progname, alternate_editor);
319 } 353 }
320 exit (EXIT_FAILURE); 354 exit (EXIT_FAILURE);