summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMichael Brown2008-03-18 01:48:23 +0100
committerMichael Brown2008-03-18 01:48:23 +0100
commit5a08b434c7ddecb9cab0f8aedd9db679ca35395c (patch)
tree661b193f21aeaf89aafaf8d92d28ae39444f85aa /src
parentMerge branch 'pxerom-pmm' (diff)
downloadipxe-5a08b434c7ddecb9cab0f8aedd9db679ca35395c.tar.gz
ipxe-5a08b434c7ddecb9cab0f8aedd9db679ca35395c.tar.xz
ipxe-5a08b434c7ddecb9cab0f8aedd9db679ca35395c.zip
[Settings] show_setting() functions return snprintf()-style length.
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.
Diffstat (limited to 'src')
-rw-r--r--src/core/settings.c17
-rw-r--r--src/hci/commands/nvo_cmd.c2
-rw-r--r--src/hci/tui/settings_ui.c2
-rw-r--r--src/include/gpxe/settings.h4
4 files changed, 11 insertions, 14 deletions
diff --git a/src/core/settings.c b/src/core/settings.c
index 42029fdcd..258fc1c7a 100644
--- a/src/core/settings.c
+++ b/src/core/settings.c
@@ -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 ) {
@@ -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,
@@ -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 );
}
/**
@@ -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,
@@ -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 ) );
}
/**
@@ -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,
@@ -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 );
}
/**
diff --git a/src/hci/commands/nvo_cmd.c b/src/hci/commands/nvo_cmd.c
index 4392787b0..4c453c77f 100644
--- a/src/hci/commands/nvo_cmd.c
+++ b/src/hci/commands/nvo_cmd.c
@@ -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;
diff --git a/src/hci/tui/settings_ui.c b/src/hci/tui/settings_ui.c
index 336af4e91..c6261c77f 100644
--- a/src/hci/tui/settings_ui.c
+++ b/src/hci/tui/settings_ui.c
@@ -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';
}
diff --git a/src/include/gpxe/settings.h b/src/include/gpxe/settings.h
index f30bbfbc7..1b9c059be 100644
--- a/src/include/gpxe/settings.h
+++ b/src/include/gpxe/settings.h
@@ -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,
@@ -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,