mirror of https://github.com/ipxe/ipxe.git
[settings] Add fetch_string_setting_copy()
parent
1284773363
commit
a128973ecb
|
@ -389,6 +389,38 @@ int fetch_string_setting ( struct settings *settings, struct setting *setting,
|
||||||
( ( len > 0 ) ? ( len - 1 ) : 0 ) );
|
( ( len > 0 ) ? ( len - 1 ) : 0 ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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
|
* Fetch value of IPv4 address setting
|
||||||
*
|
*
|
||||||
|
|
|
@ -175,6 +175,9 @@ extern int fetch_setting_len ( struct settings *settings,
|
||||||
extern int fetch_string_setting ( struct settings *settings,
|
extern int fetch_string_setting ( struct settings *settings,
|
||||||
struct setting *setting,
|
struct setting *setting,
|
||||||
char *data, size_t len );
|
char *data, size_t len );
|
||||||
|
extern int fetch_string_setting_copy ( struct settings *settings,
|
||||||
|
struct setting *setting,
|
||||||
|
char **data );
|
||||||
extern int fetch_ipv4_setting ( struct settings *settings,
|
extern int fetch_ipv4_setting ( struct settings *settings,
|
||||||
struct setting *setting, struct in_addr *inp );
|
struct setting *setting, struct in_addr *inp );
|
||||||
extern int fetch_int_setting ( struct settings *settings,
|
extern int fetch_int_setting ( struct settings *settings,
|
||||||
|
|
Loading…
Reference in New Issue