2
0
mirror of https://github.com/xcat2/xNBA.git synced 2024-11-25 19:08:35 +00:00

[settings] Add fetchf_setting_copy()

Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
Michael Brown 2013-07-18 14:46:20 +01:00
parent 72fb55e437
commit a5be7c4f29
2 changed files with 41 additions and 2 deletions

View File

@ -726,7 +726,7 @@ int fetch_setting_len ( struct settings *settings, struct setting *setting ) {
int fetch_setting_copy ( struct settings *settings, struct setting *setting,
void **data ) {
int len;
int check_len = 0;
int check_len;
/* Avoid returning uninitialised data on error */
*data = NULL;
@ -1028,7 +1028,7 @@ int setting_cmp ( struct setting *a, struct setting *b ) {
*/
/**
* Fetch and format value of setting
* Fetch formatted value of setting
*
* @v settings Settings block, or NULL to search all blocks
* @v setting Setting to fetch
@ -1064,6 +1064,43 @@ int fetchf_setting ( struct settings *settings, struct setting *setting,
return ret;
}
/**
* Fetch copy of formatted value of setting
*
* @v settings Settings block, or NULL to search all blocks
* @v setting Setting to fetch
* @v type Settings type
* @v value Buffer to allocate and fill with formatted value
* @ret len Length of formatted value, or negative error
*
* The caller is responsible for eventually freeing the allocated
* buffer.
*/
int fetchf_setting_copy ( struct settings *settings, struct setting *setting,
char **value ) {
int len;
int check_len;
/* Avoid returning uninitialised data on error */
*value = NULL;
/* Check existence, and fetch formatted value length */
len = fetchf_setting ( settings, setting, NULL, 0 );
if ( len < 0 )
return len;
/* Allocate buffer */
*value = zalloc ( len + 1 /* NUL */ );
if ( ! *value )
return -ENOMEM;
/* Fetch formatted value */
check_len = fetchf_setting ( settings, setting, *value,
( len + 1 /* NUL */ ) );
assert ( check_len == len );
return len;
}
/**
* Store formatted value of setting
*

View File

@ -310,6 +310,8 @@ extern int setting_name ( struct settings *settings, struct setting *setting,
char *buf, size_t len );
extern int fetchf_setting ( struct settings *settings, struct setting *setting,
char *buf, size_t len );
extern int fetchf_setting_copy ( struct settings *settings,
struct setting *setting, char **value );
extern int storef_setting ( struct settings *settings,
struct setting *setting,
const char *value );