|
@@ -676,6 +676,46 @@ int fetch_setting_len ( struct settings *settings, struct setting *setting ) {
|
676
|
676
|
return fetch_setting ( settings, setting, NULL, 0 );
|
677
|
677
|
}
|
678
|
678
|
|
|
679
|
+/**
|
|
680
|
+ * Fetch copy of setting
|
|
681
|
+ *
|
|
682
|
+ * @v settings Settings block, or NULL to search all blocks
|
|
683
|
+ * @v setting Setting to fetch
|
|
684
|
+ * @v data Buffer to allocate and fill with setting data
|
|
685
|
+ * @ret len Length of setting, or negative error
|
|
686
|
+ *
|
|
687
|
+ * The caller is responsible for eventually freeing the allocated
|
|
688
|
+ * buffer.
|
|
689
|
+ *
|
|
690
|
+ * To allow the caller to distinguish between a non-existent setting
|
|
691
|
+ * and an error in allocating memory for the copy, this function will
|
|
692
|
+ * return success (and a NULL buffer pointer) for a non-existent
|
|
693
|
+ * setting.
|
|
694
|
+ */
|
|
695
|
+int fetch_setting_copy ( struct settings *settings, struct setting *setting,
|
|
696
|
+ void **data ) {
|
|
697
|
+ int len;
|
|
698
|
+ int check_len = 0;
|
|
699
|
+
|
|
700
|
+ /* Avoid returning uninitialised data on error */
|
|
701
|
+ *data = NULL;
|
|
702
|
+
|
|
703
|
+ /* Fetch setting length, and return success if non-existent */
|
|
704
|
+ len = fetch_setting_len ( settings, setting );
|
|
705
|
+ if ( len < 0 )
|
|
706
|
+ return 0;
|
|
707
|
+
|
|
708
|
+ /* Allocate buffer */
|
|
709
|
+ *data = malloc ( len );
|
|
710
|
+ if ( ! *data )
|
|
711
|
+ return -ENOMEM;
|
|
712
|
+
|
|
713
|
+ /* Fetch setting */
|
|
714
|
+ check_len = fetch_setting ( settings, setting, *data, len );
|
|
715
|
+ assert ( check_len == len );
|
|
716
|
+ return len;
|
|
717
|
+}
|
|
718
|
+
|
679
|
719
|
/**
|
680
|
720
|
* Fetch value of string setting
|
681
|
721
|
*
|