Browse Source

[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.
tags/v0.9.4
Michael Brown 16 years ago
parent
commit
5a08b434c7
4 changed files with 11 additions and 14 deletions
  1. 7
    10
      src/core/settings.c
  2. 1
    1
      src/hci/commands/nvo_cmd.c
  3. 1
    1
      src/hci/tui/settings_ui.c
  4. 2
    2
      src/include/gpxe/settings.h

+ 7
- 10
src/core/settings.c View File

123
  * @v name		Configuration setting name
123
  * @v name		Configuration setting name
124
  * @v buf		Buffer to contain value
124
  * @v buf		Buffer to contain value
125
  * @v len		Length of buffer
125
  * @v len		Length of buffer
126
- * @ret rc		Return status code
126
+ * @ret len		Length of formatted value, or negative error
127
  */
127
  */
128
 int show_named_setting ( struct config_context *context, const char *name,
128
 int show_named_setting ( struct config_context *context, const char *name,
129
 			 char *buf, size_t len ) {
129
 			 char *buf, size_t len ) {
180
  * @v setting		Configuration setting
180
  * @v setting		Configuration setting
181
  * @v buf		Buffer to contain value
181
  * @v buf		Buffer to contain value
182
  * @v len		Length of buffer
182
  * @v len		Length of buffer
183
- * @ret rc		Return status code
183
+ * @ret len		Length of formatted value, or negative error
184
  */
184
  */
185
 static int show_string ( struct config_context *context,
185
 static int show_string ( struct config_context *context,
186
 			 struct config_setting *setting,
186
 			 struct config_setting *setting,
190
 	option = find_dhcp_option ( context->options, setting->tag );
190
 	option = find_dhcp_option ( context->options, setting->tag );
191
 	if ( ! option )
191
 	if ( ! option )
192
 		return -ENODATA;
192
 		return -ENODATA;
193
-	dhcp_snprintf ( buf, len, option );
194
-	return 0;
193
+	return dhcp_snprintf ( buf, len, option );
195
 }
194
 }
196
 
195
 
197
 /**
196
 /**
229
  * @v setting		Configuration setting
228
  * @v setting		Configuration setting
230
  * @v buf		Buffer to contain value
229
  * @v buf		Buffer to contain value
231
  * @v len		Length of buffer
230
  * @v len		Length of buffer
232
- * @ret rc		Return status code
231
+ * @ret len		Length of formatted value, or negative error
233
  */
232
  */
234
 static int show_ipv4 ( struct config_context *context,
233
 static int show_ipv4 ( struct config_context *context,
235
 		       struct config_setting *setting,
234
 		       struct config_setting *setting,
241
 	if ( ! option )
240
 	if ( ! option )
242
 		return -ENODATA;
241
 		return -ENODATA;
243
 	dhcp_ipv4_option ( option, &ipv4 );
242
 	dhcp_ipv4_option ( option, &ipv4 );
244
-	snprintf ( buf, len, inet_ntoa ( ipv4 ) );
245
-	return 0;
243
+	return snprintf ( buf, len, inet_ntoa ( ipv4 ) );
246
 }
244
 }
247
 
245
 
248
 /**
246
 /**
283
  * @v setting		Configuration setting
281
  * @v setting		Configuration setting
284
  * @v buf		Buffer to contain value
282
  * @v buf		Buffer to contain value
285
  * @v len		Length of buffer
283
  * @v len		Length of buffer
286
- * @ret rc		Return status code
284
+ * @ret len		Length of formatted value, or negative error
287
  */
285
  */
288
 static int show_int ( struct config_context *context,
286
 static int show_int ( struct config_context *context,
289
 		      struct config_setting *setting,
287
 		      struct config_setting *setting,
295
 	if ( ! option )
293
 	if ( ! option )
296
 		return -ENODATA;
294
 		return -ENODATA;
297
 	num = dhcp_num_option ( option );
295
 	num = dhcp_num_option ( option );
298
-	snprintf ( buf, len, "%ld", num );
299
-	return 0;
296
+	return snprintf ( buf, len, "%ld", num );
300
 }
297
 }
301
 
298
 
302
 /**
299
 /**

+ 1
- 1
src/hci/commands/nvo_cmd.c View File

28
 
28
 
29
 	dummy_context.options = ugly_nvo_hack->options;
29
 	dummy_context.options = ugly_nvo_hack->options;
30
 	if ( ( rc = show_named_setting ( &dummy_context, argv[1], buf,
30
 	if ( ( rc = show_named_setting ( &dummy_context, argv[1], buf,
31
-					 sizeof ( buf ) ) ) != 0 ) {
31
+					 sizeof ( buf ) ) ) < 0 ) {
32
 		printf ( "Could not find \"%s\": %s\n",
32
 		printf ( "Could not find \"%s\": %s\n",
33
 			 argv[1], strerror ( -rc ) );
33
 			 argv[1], strerror ( -rc ) );
34
 		return 1;
34
 		return 1;

+ 1
- 1
src/hci/tui/settings_ui.c View File

118
 
118
 
119
 	/* Read current setting value */
119
 	/* Read current setting value */
120
 	if ( show_setting ( widget->context, widget->setting,
120
 	if ( show_setting ( widget->context, widget->setting,
121
-			    widget->value, sizeof ( widget->value ) ) != 0 ) {
121
+			    widget->value, sizeof ( widget->value ) ) < 0 ) {
122
 		widget->value[0] = '\0';
122
 		widget->value[0] = '\0';
123
 	}	
123
 	}	
124
 
124
 

+ 2
- 2
src/include/gpxe/settings.h View File

48
 	 * @v setting		Configuration setting
48
 	 * @v setting		Configuration setting
49
 	 * @v buf		Buffer to contain value
49
 	 * @v buf		Buffer to contain value
50
 	 * @v len		Length of buffer
50
 	 * @v len		Length of buffer
51
-	 * @ret rc		Return status code
51
+	 * @ret len		Length of formatted value, or negative error
52
 	 */
52
 	 */
53
 	int ( * show ) ( struct config_context *context,
53
 	int ( * show ) ( struct config_context *context,
54
 			 struct config_setting *setting,
54
 			 struct config_setting *setting,
108
  * @v setting		Configuration setting
108
  * @v setting		Configuration setting
109
  * @v buf		Buffer to contain value
109
  * @v buf		Buffer to contain value
110
  * @v len		Length of buffer
110
  * @v len		Length of buffer
111
- * @ret rc		Return status code
111
+ * @ret len		Length of formatted value, or negative error
112
  */
112
  */
113
 static inline int show_setting ( struct config_context *context,
113
 static inline int show_setting ( struct config_context *context,
114
 				 struct config_setting *setting,
114
 				 struct config_setting *setting,

Loading…
Cancel
Save