Fix argv parsing
authorhpa <hpa>
Tue, 21 Dec 2004 02:47:08 +0000 (02:47 +0000)
committerhpa <hpa>
Tue, 21 Dec 2004 02:47:08 +0000 (02:47 +0000)
com32/lib/sys/argv.c
com32/lib/sys/entry.S

index 4c83589..b4a5728 100644 (file)
@@ -44,12 +44,13 @@ void *__mem_end = &_end;     /* Global variable for use by malloc() */
 
 int __parse_argv(char ***argv, const char *str)
 {
+  char argv0[] = "";
   char *mem = __mem_end;
   const char *p = str;
   char *q = mem;
   char *r;
   char **arg;
-  int wasspace = 0;
+  int wasspace = 1;
   int argc = 1;
 
   /* First copy the string, turning whitespace runs into nulls */
@@ -77,9 +78,12 @@ int __parse_argv(char ***argv, const char *str)
   /* Now create argv */
   arg = ALIGN_UP(q,char *);
   *argv = arg;
-  *arg++ = mem;                        /* argv[0] */
-
+  *arg++ = argv0;              /* argv[0] */
+  
   q--;                         /* Point q to final null */
+  if ( mem < q )
+    *arg++ = mem;              /* argv[1] */
+
   for ( r = mem ; r < q ; r++ ) {
     if ( *r == '\0' ) {
       *arg++ = r+1;
index 26efde0..38e4c88 100644 (file)
@@ -58,7 +58,7 @@ _start:
 1:             rep ; movsl
 
                # Parse the command line (assumes REGPARM)
-               movl $__com32+4,%edx            # Command line
+               movl __com32+4,%edx             # Command line
                pushl %edx                      # Make space for argv
                movl %esp,%eax
                call __parse_argv