Преглед изворни кода

[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 година
родитељ
комит
5a08b434c7
4 измењених фајлова са 11 додато и 14 уклоњено
  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 Прегледај датотеку

@@ -123,7 +123,7 @@ find_or_build_config_setting ( const char *name,
123 123
  * @v name		Configuration setting name
124 124
  * @v buf		Buffer to contain value
125 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 128
 int show_named_setting ( struct config_context *context, const char *name,
129 129
 			 char *buf, size_t len ) {
@@ -180,7 +180,7 @@ int set_setting ( struct config_context *context,
180 180
  * @v setting		Configuration setting
181 181
  * @v buf		Buffer to contain value
182 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 185
 static int show_string ( struct config_context *context,
186 186
 			 struct config_setting *setting,
@@ -190,8 +190,7 @@ static int show_string ( struct config_context *context,
190 190
 	option = find_dhcp_option ( context->options, setting->tag );
191 191
 	if ( ! option )
192 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,7 +228,7 @@ struct config_setting_type config_setting_type_string __config_setting_type = {
229 228
  * @v setting		Configuration setting
230 229
  * @v buf		Buffer to contain value
231 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 233
 static int show_ipv4 ( struct config_context *context,
235 234
 		       struct config_setting *setting,
@@ -241,8 +240,7 @@ static int show_ipv4 ( struct config_context *context,
241 240
 	if ( ! option )
242 241
 		return -ENODATA;
243 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,7 +281,7 @@ struct config_setting_type config_setting_type_ipv4 __config_setting_type = {
283 281
  * @v setting		Configuration setting
284 282
  * @v buf		Buffer to contain value
285 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 286
 static int show_int ( struct config_context *context,
289 287
 		      struct config_setting *setting,
@@ -295,8 +293,7 @@ static int show_int ( struct config_context *context,
295 293
 	if ( ! option )
296 294
 		return -ENODATA;
297 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 Прегледај датотеку

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

+ 1
- 1
src/hci/tui/settings_ui.c Прегледај датотеку

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

+ 2
- 2
src/include/gpxe/settings.h Прегледај датотеку

@@ -48,7 +48,7 @@ struct config_setting_type {
48 48
 	 * @v setting		Configuration setting
49 49
 	 * @v buf		Buffer to contain value
50 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 53
 	int ( * show ) ( struct config_context *context,
54 54
 			 struct config_setting *setting,
@@ -108,7 +108,7 @@ struct config_setting {
108 108
  * @v setting		Configuration setting
109 109
  * @v buf		Buffer to contain value
110 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 113
 static inline int show_setting ( struct config_context *context,
114 114
 				 struct config_setting *setting,

Loading…
Откажи
Сачувај