summaryrefslogtreecommitdiffstats
path: root/src/core/settings.c
diff options
context:
space:
mode:
authorMichael Brown2009-01-27 20:13:47 +0100
committerMichael Brown2009-01-27 20:13:47 +0100
commita128973ecbc3bc98d0140436e80ef8ee1030dc7c (patch)
tree85612fea9eb0ec720ba6c74c36a15d6693b0f115 /src/core/settings.c
parent[tftp] Temporary fix for conveying TFTP block size to callers (diff)
downloadipxe-a128973ecbc3bc98d0140436e80ef8ee1030dc7c.tar.gz
ipxe-a128973ecbc3bc98d0140436e80ef8ee1030dc7c.tar.xz
ipxe-a128973ecbc3bc98d0140436e80ef8ee1030dc7c.zip
[settings] Add fetch_string_setting_copy()
Diffstat (limited to 'src/core/settings.c')
-rw-r--r--src/core/settings.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/core/settings.c b/src/core/settings.c
index 2d9c096e..09033bd9 100644
--- a/src/core/settings.c
+++ b/src/core/settings.c
@@ -390,6 +390,38 @@ int fetch_string_setting ( struct settings *settings, struct setting *setting,
}
/**
+ * Fetch value of string setting
+ *
+ * @v settings Settings block, or NULL to search all blocks
+ * @v setting Setting to fetch
+ * @v data Buffer to allocate and fill with setting string data
+ * @ret len Length of string setting, or negative error
+ *
+ * The resulting string is guaranteed to be correctly NUL-terminated.
+ * The returned length will be the length of the underlying setting
+ * data. The caller is responsible for eventually freeing the
+ * allocated buffer.
+ */
+int fetch_string_setting_copy ( struct settings *settings,
+ struct setting *setting,
+ char **data ) {
+ int len;
+ int check_len;
+
+ len = fetch_setting_len ( settings, setting );
+ if ( len < 0 )
+ return len;
+
+ *data = malloc ( len + 1 );
+ if ( ! *data )
+ return -ENOMEM;
+
+ fetch_string_setting ( settings, setting, *data, ( len + 1 ) );
+ assert ( check_len == len );
+ return len;
+}
+
+/**
* Fetch value of IPv4 address setting
*
* @v settings Settings block, or NULL to search all blocks