[xiph-cvs] cvs commit: win32sdk execwait.c

Chris Wolf cwolf at xiph.org
Sun Oct 21 13:32:04 PDT 2001



cwolf       01/10/21 13:32:03

  Modified:    .        execwait.c
  Log:
  Support arbitrarily long command lines

Revision  Changes    Path
1.2       +17 -12    win32sdk/execwait.c

Index: execwait.c
===================================================================
RCS file: /usr/local/cvsroot/win32sdk/execwait.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- execwait.c	2001/10/18 17:20:30	1.1
+++ execwait.c	2001/10/21 20:32:03	1.2
@@ -1,12 +1,11 @@
 /*
- * $Id: execwait.c,v 1.1 2001/10/18 17:20:30 cwolf Exp $
+ * $Id: execwait.c,v 1.2 2001/10/21 20:32:03 cwolf Exp $
  */
 #include <windows.h>
 #include <winbase.h>
 #include <stdio.h>
 #include <string.h>
 
-#define BUF_SIZE 1000
 
 /**
  * Execute a command and wait for it's completion.
@@ -18,8 +17,9 @@
   STARTUPINFO si;
   PROCESS_INFORMATION pi;
 
-  char cmdline[BUF_SIZE+1] = "";
-  int i, c=0;
+  char *cmdline;
+  int   argend;
+  int   i;
 
   if(argc==1)
   {
@@ -27,17 +27,22 @@
     exit(1);
   }
 
-  for(i=1;i<argc;i++)
+  for(i=1, 
+      cmdline = (char *)malloc(strlen(argv[1]) + 1),
+      *cmdline = '\0';
+      i<argc; i++)
   {
-    if(strlen(argv[i])>(size_t)(BUF_SIZE-c))
+    (void)strcat(cmdline, argv[i]);
+    (void)strcat(cmdline, " ");
+
+    argend = strlen(cmdline);
+
+    if (i+1 < argc)
     {
-      (void)fprintf(stderr, "Command line too long\n");
-      exit(1);
+      cmdline = (char *)realloc(cmdline, 
+                                strlen(cmdline) + strlen(argv[i+1]) + 1);
+      *(cmdline + argend) = '\0'; // restore null terminator
     }
-
-    strcat(cmdline, argv[i]);
-    strcat(cmdline, " ");
-    c+=strlen(argv[i]);
   }
 
   memset(&si, 0, sizeof(si));

--- >8 ----
List archives:  http://www.xiph.org/archives/
Ogg project homepage: http://www.xiph.org/ogg/
To unsubscribe from this list, send a message to 'cvs-request at xiph.org'
containing only the word 'unsubscribe' in the body.  No subject is needed.
Unsubscribe messages sent to the list will be ignored/filtered.



More information about the commits mailing list