summaryrefslogtreecommitdiff
blob: 0b9b7fa3c56d1c80cda8d2dc363bc6b5cb7a91b9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
Author: Niko Tyni <ntyni@iki.fi>
Description: Allow empty strings as command-line parameters
--- a/src/speedy_frontend.c
+++ b/src/speedy_frontend.c
@@ -535,7 +535,26 @@
 	    ADD_STRING(b, s, l);
 	}
     }
+    /* Terminate with zero-length string */
+    ADDCHAR(b, 0);
+}
+
+/* Copy a block of strings into the buffer, including empty strings */
+static void add_strings_with_empty(register SpeedyBuf *b, register const char * const * p)
+{
+    int l;
+    register const char *s;
 
+    /* Add strings in p array */
+    for (; (s = *p); ++p) {
+	if ((l = strlen(s))) {
+	    ADD_STRING(b, s, l);
+	} else {
+	    /* add a 1-byte long string containing just '\0' */
+	    l = 1;
+	    ADD_STRING(b, s, l);
+	}
+    }
     /* Terminate with zero-length string */
     ADDCHAR(b, 0);
 }
@@ -560,7 +579,7 @@
 
     /* Add env and argv */
     add_strings(sb, envp);
-    add_strings(sb, scr_argv+1);
+    add_strings_with_empty(sb, scr_argv+1);
 
     /* Put script filename into buffer */
     add_string(sb, script_fname, strlen(script_fname));