|
@@ -30,17 +30,37 @@ static int show_exec ( int argc, char **argv ) {
|
30
|
30
|
}
|
31
|
31
|
|
32
|
32
|
static int set_exec ( int argc, char **argv ) {
|
|
33
|
+ size_t len;
|
|
34
|
+ int i;
|
33
|
35
|
int rc;
|
34
|
36
|
|
35
|
|
- if ( argc != 3 ) {
|
|
37
|
+ if ( argc < 3 ) {
|
36
|
38
|
printf ( "Syntax: %s <identifier> <value>\n", argv[0] );
|
37
|
39
|
return 1;
|
38
|
40
|
}
|
39
|
41
|
|
40
|
|
- if ( ( rc = storef_named_setting ( argv[1], argv[2] ) ) != 0 ) {
|
41
|
|
- printf ( "Could not set \"%s\"=\"%s\": %s\n",
|
42
|
|
- argv[1], argv[2], strerror ( rc ) );
|
43
|
|
- return 1;
|
|
42
|
+ /* Determine total length of command line */
|
|
43
|
+ len = 1; /* NUL */
|
|
44
|
+ for ( i = 2 ; i < argc ; i++ )
|
|
45
|
+ len += ( 1 /* possible space */ + strlen ( argv[i] ) );
|
|
46
|
+
|
|
47
|
+ {
|
|
48
|
+ char buf[len];
|
|
49
|
+ char *ptr = buf;
|
|
50
|
+
|
|
51
|
+ /* Assemble command line */
|
|
52
|
+ buf[0] = '\0';
|
|
53
|
+ for ( i = 2 ; i < argc ; i++ ) {
|
|
54
|
+ ptr += sprintf ( ptr, "%s%s", ( buf[0] ? " " : "" ),
|
|
55
|
+ argv[i] );
|
|
56
|
+ }
|
|
57
|
+ assert ( ptr < ( buf + len ) );
|
|
58
|
+
|
|
59
|
+ if ( ( rc = storef_named_setting ( argv[1], buf ) ) != 0 ) {
|
|
60
|
+ printf ( "Could not set \"%s\"=\"%s\": %s\n",
|
|
61
|
+ argv[1], buf, strerror ( rc ) );
|
|
62
|
+ return 1;
|
|
63
|
+ }
|
44
|
64
|
}
|
45
|
65
|
|
46
|
66
|
return 0;
|