Skip to content

Commit

Permalink
[Settings] show_setting() functions return snprintf()-style length.
Browse files Browse the repository at this point in the history
show_setting() and related functions now return an "actual length" in the
style of snprintf().  This is to allow consumers to allocate buffers large
enough to hold the formatted setting.
  • Loading branch information
Michael Brown committed Mar 18, 2008
1 parent 08b19ab commit 5a08b43
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 14 deletions.
17 changes: 7 additions & 10 deletions src/core/settings.c
Expand Up @@ -123,7 +123,7 @@ find_or_build_config_setting ( const char *name,
* @v name Configuration setting name
* @v buf Buffer to contain value
* @v len Length of buffer
* @ret rc Return status code
* @ret len Length of formatted value, or negative error
*/
int show_named_setting ( struct config_context *context, const char *name,
char *buf, size_t len ) {
Expand Down Expand Up @@ -180,7 +180,7 @@ int set_setting ( struct config_context *context,
* @v setting Configuration setting
* @v buf Buffer to contain value
* @v len Length of buffer
* @ret rc Return status code
* @ret len Length of formatted value, or negative error
*/
static int show_string ( struct config_context *context,
struct config_setting *setting,
Expand All @@ -190,8 +190,7 @@ static int show_string ( struct config_context *context,
option = find_dhcp_option ( context->options, setting->tag );
if ( ! option )
return -ENODATA;
dhcp_snprintf ( buf, len, option );
return 0;
return dhcp_snprintf ( buf, len, option );
}

/**
Expand Down Expand Up @@ -229,7 +228,7 @@ struct config_setting_type config_setting_type_string __config_setting_type = {
* @v setting Configuration setting
* @v buf Buffer to contain value
* @v len Length of buffer
* @ret rc Return status code
* @ret len Length of formatted value, or negative error
*/
static int show_ipv4 ( struct config_context *context,
struct config_setting *setting,
Expand All @@ -241,8 +240,7 @@ static int show_ipv4 ( struct config_context *context,
if ( ! option )
return -ENODATA;
dhcp_ipv4_option ( option, &ipv4 );
snprintf ( buf, len, inet_ntoa ( ipv4 ) );
return 0;
return snprintf ( buf, len, inet_ntoa ( ipv4 ) );
}

/**
Expand Down Expand Up @@ -283,7 +281,7 @@ struct config_setting_type config_setting_type_ipv4 __config_setting_type = {
* @v setting Configuration setting
* @v buf Buffer to contain value
* @v len Length of buffer
* @ret rc Return status code
* @ret len Length of formatted value, or negative error
*/
static int show_int ( struct config_context *context,
struct config_setting *setting,
Expand All @@ -295,8 +293,7 @@ static int show_int ( struct config_context *context,
if ( ! option )
return -ENODATA;
num = dhcp_num_option ( option );
snprintf ( buf, len, "%ld", num );
return 0;
return snprintf ( buf, len, "%ld", num );
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/hci/commands/nvo_cmd.c
Expand Up @@ -28,7 +28,7 @@ static int show_exec ( int argc, char **argv ) {

dummy_context.options = ugly_nvo_hack->options;
if ( ( rc = show_named_setting ( &dummy_context, argv[1], buf,
sizeof ( buf ) ) ) != 0 ) {
sizeof ( buf ) ) ) < 0 ) {
printf ( "Could not find \"%s\": %s\n",
argv[1], strerror ( -rc ) );
return 1;
Expand Down
2 changes: 1 addition & 1 deletion src/hci/tui/settings_ui.c
Expand Up @@ -118,7 +118,7 @@ static void load_setting ( struct setting_widget *widget ) {

/* Read current setting value */
if ( show_setting ( widget->context, widget->setting,
widget->value, sizeof ( widget->value ) ) != 0 ) {
widget->value, sizeof ( widget->value ) ) < 0 ) {
widget->value[0] = '\0';
}

Expand Down
4 changes: 2 additions & 2 deletions src/include/gpxe/settings.h
Expand Up @@ -48,7 +48,7 @@ struct config_setting_type {
* @v setting Configuration setting
* @v buf Buffer to contain value
* @v len Length of buffer
* @ret rc Return status code
* @ret len Length of formatted value, or negative error
*/
int ( * show ) ( struct config_context *context,
struct config_setting *setting,
Expand Down Expand Up @@ -108,7 +108,7 @@ struct config_setting {
* @v setting Configuration setting
* @v buf Buffer to contain value
* @v len Length of buffer
* @ret rc Return status code
* @ret len Length of formatted value, or negative error
*/
static inline int show_setting ( struct config_context *context,
struct config_setting *setting,
Expand Down

0 comments on commit 5a08b43

Please sign in to comment.