diff options
author | Michael Brown | 2011-03-22 18:29:08 +0100 |
---|---|---|
committer | Michael Brown | 2011-03-22 20:55:05 +0100 |
commit | aebba8f6eb29ad41a4ed1b2dc821719b64f2b576 (patch) | |
tree | 6d69d16637eac4f528eda53bffda0c82254f5e1e /src/hci/commands | |
parent | [settings] Formalise notion of setting applicability (diff) | |
download | ipxe-aebba8f6eb29ad41a4ed1b2dc821719b64f2b576.tar.gz ipxe-aebba8f6eb29ad41a4ed1b2dc821719b64f2b576.tar.xz ipxe-aebba8f6eb29ad41a4ed1b2dc821719b64f2b576.zip |
[settings] Use concat_args() in "set" command
Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src/hci/commands')
-rw-r--r-- | src/hci/commands/nvo_cmd.c | 44 |
1 files changed, 20 insertions, 24 deletions
diff --git a/src/hci/commands/nvo_cmd.c b/src/hci/commands/nvo_cmd.c index d8621abc..35c9d473 100644 --- a/src/hci/commands/nvo_cmd.c +++ b/src/hci/commands/nvo_cmd.c @@ -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 */ |