|
@@ -625,6 +625,11 @@ int fetch_string_setting ( struct settings *settings, struct setting *setting,
|
625
|
625
|
* The returned length will be the length of the underlying setting
|
626
|
626
|
* data. The caller is responsible for eventually freeing the
|
627
|
627
|
* allocated buffer.
|
|
628
|
+ *
|
|
629
|
+ * To allow the caller to distinguish between a non-existent setting
|
|
630
|
+ * and an error in allocating memory for the copy, this function will
|
|
631
|
+ * return success (and a NULL buffer pointer) for a non-existent
|
|
632
|
+ * setting.
|
628
|
633
|
*/
|
629
|
634
|
int fetch_string_setting_copy ( struct settings *settings,
|
630
|
635
|
struct setting *setting,
|
|
@@ -632,16 +637,20 @@ int fetch_string_setting_copy ( struct settings *settings,
|
632
|
637
|
int len;
|
633
|
638
|
int check_len = 0;
|
634
|
639
|
|
|
640
|
+ /* Avoid returning uninitialised data on error */
|
635
|
641
|
*data = NULL;
|
636
|
642
|
|
|
643
|
+ /* Fetch setting length, and return success if non-existent */
|
637
|
644
|
len = fetch_setting_len ( settings, setting );
|
638
|
645
|
if ( len < 0 )
|
639
|
|
- return len;
|
|
646
|
+ return 0;
|
640
|
647
|
|
|
648
|
+ /* Allocate string buffer */
|
641
|
649
|
*data = malloc ( len + 1 );
|
642
|
650
|
if ( ! *data )
|
643
|
651
|
return -ENOMEM;
|
644
|
652
|
|
|
653
|
+ /* Fetch setting */
|
645
|
654
|
check_len = fetch_string_setting ( settings, setting, *data,
|
646
|
655
|
( len + 1 ) );
|
647
|
656
|
assert ( check_len == len );
|