Browse Source

[settings] Add fetch_string_setting_copy()

tags/v0.9.7
Michael Brown 16 years ago
parent
commit
a128973ecb
2 changed files with 35 additions and 0 deletions
  1. 32
    0
      src/core/settings.c
  2. 3
    0
      src/include/gpxe/settings.h

+ 32
- 0
src/core/settings.c View File

@@ -389,6 +389,38 @@ int fetch_string_setting ( struct settings *settings, struct setting *setting,
389 389
 			       ( ( len > 0 ) ? ( len - 1 ) : 0 ) );
390 390
 }
391 391
 
392
+/**
393
+ * Fetch value of string setting
394
+ *
395
+ * @v settings		Settings block, or NULL to search all blocks
396
+ * @v setting		Setting to fetch
397
+ * @v data		Buffer to allocate and fill with setting string data
398
+ * @ret len		Length of string setting, or negative error
399
+ *
400
+ * The resulting string is guaranteed to be correctly NUL-terminated.
401
+ * The returned length will be the length of the underlying setting
402
+ * data.  The caller is responsible for eventually freeing the
403
+ * allocated buffer.
404
+ */
405
+int fetch_string_setting_copy ( struct settings *settings,
406
+				struct setting *setting,
407
+				char **data ) {
408
+	int len;
409
+	int check_len;
410
+
411
+	len = fetch_setting_len ( settings, setting );
412
+	if ( len < 0 )
413
+		return len;
414
+
415
+	*data = malloc ( len + 1 );
416
+	if ( ! *data )
417
+		return -ENOMEM;
418
+
419
+	fetch_string_setting ( settings, setting, *data, ( len + 1 ) );
420
+	assert ( check_len == len );
421
+	return len;
422
+}
423
+
392 424
 /**
393 425
  * Fetch value of IPv4 address setting
394 426
  *

+ 3
- 0
src/include/gpxe/settings.h View File

@@ -175,6 +175,9 @@ extern int fetch_setting_len ( struct settings *settings,
175 175
 extern int fetch_string_setting ( struct settings *settings,
176 176
 				  struct setting *setting,
177 177
 				  char *data, size_t len );
178
+extern int fetch_string_setting_copy ( struct settings *settings,
179
+				       struct setting *setting,
180
+				       char **data );
178 181
 extern int fetch_ipv4_setting ( struct settings *settings,
179 182
 				struct setting *setting, struct in_addr *inp );
180 183
 extern int fetch_int_setting ( struct settings *settings,

Loading…
Cancel
Save