]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[settings] Use concat_args() in "set" command
authorMichael Brown <mcb30@ipxe.org>
Tue, 22 Mar 2011 17:29:08 +0000 (17:29 +0000)
committerMichael Brown <mcb30@ipxe.org>
Tue, 22 Mar 2011 19:55:05 +0000 (19:55 +0000)
Signed-off-by: Michael Brown <mcb30@ipxe.org>
src/hci/commands/nvo_cmd.c
src/include/ipxe/errfile.h

index d8621abc607d2f02f5916241b3ca1cee603dbccd..35c9d473346be20c4890e320fb52a5f706c0db03 100644 (file)
@@ -99,42 +99,38 @@ static struct command_descriptor set_cmd =
 static int set_exec ( int argc, char **argv ) {
        struct set_options opts;
        const char *name;
-       size_t len;
-       int i;
+       char *value;
        int rc;
 
        /* Parse options */
        if ( ( rc = parse_options ( argc, argv, &set_cmd, &opts ) ) != 0 )
-               return rc;
+               goto err_parse_options;
 
        /* Parse setting name */
        name = argv[optind];
 
-       /* Determine total length of command line */
-       len = 1; /* NUL */
-       for ( i = optind + 1 ; i < argc ; i++ )
-               len += ( 1 /* possible space */ + strlen ( argv[i] ) );
+       /* Parse setting value */
+       value = concat_args ( &argv[ optind + 1 ] );
+       if ( ! value ) {
+               rc = -ENOMEM;
+               goto err_concat_args;
+       }
 
-       {
-               char buf[len];
-               char *ptr = buf;
-
-               /* Assemble command line */
-               buf[0] = '\0';
-               for ( i = optind + 1 ; i < argc ; i++ ) {
-                       ptr += sprintf ( ptr, "%s%s", ( buf[0] ? " " : "" ),
-                                        argv[i] );
-               }
-               assert ( ptr < ( buf + len ) );
-
-               if ( ( rc = storef_named_setting ( name, buf ) ) != 0 ) {
-                       printf ( "Could not set \"%s\"=\"%s\": %s\n",
-                                name, buf, strerror ( rc ) );
-                       return rc;
-               }
+       /* Determine total length of command line */
+       if ( ( rc = storef_named_setting ( name, value ) ) != 0 ) {
+               printf ( "Could not set \"%s\"=\"%s\": %s\n",
+                        name, value, strerror ( rc ) );
+               goto err_store;
        }
 
+       free ( value );
        return 0;
+
+ err_store:
+       free ( value );
+ err_concat_args:
+ err_parse_options:
+       return rc;
 }
 
 /** "clear" options */
index 7968c4f517cccdafdf3648386184dcc3be65e5d7..3073383baa22326003e7065f8bc0582714a74a08 100644 (file)
@@ -238,6 +238,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
 #define ERRFILE_sanboot_cmd          ( ERRFILE_OTHER | 0x00200000 )
 #define ERRFILE_bofm                 ( ERRFILE_OTHER | 0x00210000 )
 #define ERRFILE_prompt               ( ERRFILE_OTHER | 0x00220000 )
+#define ERRFILE_nvo_cmd                      ( ERRFILE_OTHER | 0x00230000 )
 
 /** @} */