]> code.delx.au - gnu-emacs/blobdiff - nt/cmdproxy.c
* lisp/progmodes/sql.el: Remove comment link to defunct viewcvs url.
[gnu-emacs] / nt / cmdproxy.c
index edf7b364671d3a8f1791b57b1b20b6dd82f7d0b3..4f2d113a900d9f07d4a0bccbea8170a7f2217465 100644 (file)
@@ -1,8 +1,8 @@
 /* Proxy shell designed for use with Emacs on Windows 95 and NT.
    Copyright (C) 1997, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
-     2008  Free Software Foundation, Inc.
+     2008, 2009, 2010  Free Software Foundation, Inc.
 
-   Accepts subset of Unix sh(1) command-line options, for compatability
+   Accepts subset of Unix sh(1) command-line options, for compatibility
    with elisp code written for Unix.  When possible, executes external
    programs directly (a common use of /bin/sh by Emacs), otherwise
    invokes the user-specified command processor to handle built-in shell
@@ -35,6 +35,9 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 #include <stdlib.h>  /* getenv */
 #include <string.h>  /* strlen */
 
+/* We don't want to include stdio.h because we are already duplicating
+   lots of it here */
+extern int _snprintf (char *buffer, size_t count, const char *format, ...);
 
 /*******  Mock C library routines  *********************************/
 
@@ -341,7 +344,7 @@ console_event_handler (DWORD event)
     case CTRL_BREAK_EVENT:
       if (!interactive)
        {
-         /* Both command.com and cmd.exe have the annoying behaviour of
+         /* Both command.com and cmd.exe have the annoying behavior of
             prompting "Terminate batch job (y/n)?" when interrupted
             while running a batch file, even if running in
             non-interactive (-c) mode.  Try to make up for this
@@ -513,10 +516,10 @@ main (int argc, char ** argv)
     {
       ++argv;
       /* Act on switches we recognize (mostly single letter switches,
-        except for -e); all unrecognised switches and extra args are
+        except for -e); all unrecognized switches and extra args are
         passed on to real shell if used (only really of benefit for
         interactive use, but allow for batch use as well).  Accept / as
-        switch char for compatability with cmd.exe.  */
+        switch char for compatibility with cmd.exe.  */
       if (((*argv)[0] == '-' || (*argv)[0] == '/') && (*argv)[1] != '\0')
        {
          if (((*argv)[1] == 'c' || (*argv)[1] == 'C') && ((*argv)[2] == '\0'))
@@ -604,6 +607,7 @@ main (int argc, char ** argv)
     {
       char * p;
       int    extra_arg_space = 0;
+      int    maxlen, remlen;
       int    run_command_dot_com;
 
       progname = getenv ("COMSPEC");
@@ -635,21 +639,27 @@ main (int argc, char ** argv)
             case path contains spaces (fortunately it can't contain
             quotes, since they are illegal in path names).  */
 
-         buf = p = alloca (strlen (progname) + extra_arg_space +
-                           strlen (cmdline) + 16);
+         remlen = maxlen =
+           strlen (progname) + extra_arg_space + strlen (cmdline) + 16;
+         buf = p = alloca (maxlen + 1);
 
          /* Quote progname in case it contains spaces.  */
-         p += wsprintf (p, "\"%s\"", progname);
+         p += _snprintf (p, remlen, "\"%s\"", progname);
+         remlen = maxlen - (p - buf);
 
          /* Include pass_through_args verbatim; these are just switches
              so should not need quoting.  */
          for (argv = pass_through_args; *argv != NULL; ++argv)
-           p += wsprintf (p, " %s", *argv);
+           {
+             p += _snprintf (p, remlen, " %s", *argv);
+             remlen = maxlen - (p - buf);
+           }
 
          if (run_command_dot_com)
-           wsprintf(p, " /e:%d /c %s", envsize, cmdline);
+           _snprintf (p, remlen, " /e:%d /c %s", envsize, cmdline);
          else
-           wsprintf(p, " /c %s", cmdline);
+           _snprintf (p, remlen, " /c %s", cmdline);
+         remlen = maxlen - (p - buf);
          cmdline = buf;
        }
       else
@@ -669,19 +679,27 @@ main (int argc, char ** argv)
          else
            path[0] = '\0';
 
-         cmdline = p = alloca (strlen (progname) + extra_arg_space +
-                               strlen (path) + 13);
+         remlen = maxlen =
+           strlen (progname) + extra_arg_space + strlen (path) + 13;
+         cmdline = p = alloca (maxlen + 1);
 
          /* Quote progname in case it contains spaces.  */
-         p += wsprintf (p, "\"%s\" %s", progname, path);
+         p += _snprintf (p, remlen, "\"%s\" %s", progname, path);
+         remlen = maxlen - (p - cmdline);
 
          /* Include pass_through_args verbatim; these are just switches
              so should not need quoting.  */
          for (argv = pass_through_args; *argv != NULL; ++argv)
-           p += wsprintf (p, " %s", *argv);
+           {
+             p += _snprintf (p, remlen, " %s", *argv);
+             remlen = maxlen - (p - cmdline);
+           }
 
          if (run_command_dot_com)
-           wsprintf (p, " /e:%d", envsize);
+           {
+             _snprintf (p, remlen, " /e:%d", envsize);
+             remlen = maxlen - (p - cmdline);
+           }
        }
     }