|
@@ -1332,6 +1332,45 @@ int fetchf_named_setting ( const char *name,
|
1332
|
1332
|
return len;
|
1333
|
1333
|
}
|
1334
|
1334
|
|
|
1335
|
+/**
|
|
1336
|
+ * Fetch and format copy of value of named setting
|
|
1337
|
+ *
|
|
1338
|
+ * @v name Name of setting
|
|
1339
|
+ * @v data Buffer to allocate and fill with formatted value
|
|
1340
|
+ * @ret len Length of formatted value, or negative error
|
|
1341
|
+ *
|
|
1342
|
+ * The caller is responsible for eventually freeing the allocated
|
|
1343
|
+ * buffer.
|
|
1344
|
+ *
|
|
1345
|
+ * To allow the caller to distinguish between a non-existent setting
|
|
1346
|
+ * and an error in allocating memory for the copy, this function will
|
|
1347
|
+ * return success (and a NULL buffer pointer) for a non-existent
|
|
1348
|
+ * setting.
|
|
1349
|
+ */
|
|
1350
|
+int fetchf_named_setting_copy ( const char *name, char **data ) {
|
|
1351
|
+ int len;
|
|
1352
|
+ int check_len;
|
|
1353
|
+
|
|
1354
|
+ /* Avoid returning uninitialised data on error */
|
|
1355
|
+ *data = NULL;
|
|
1356
|
+
|
|
1357
|
+ /* Fetch formatted value length, and return success if non-existent */
|
|
1358
|
+ len = fetchf_named_setting ( name, NULL, 0, NULL, 0 );
|
|
1359
|
+ if ( len < 0 )
|
|
1360
|
+ return 0;
|
|
1361
|
+
|
|
1362
|
+ /* Allocate buffer */
|
|
1363
|
+ *data = malloc ( len + 1 /* NUL */ );
|
|
1364
|
+ if ( ! *data )
|
|
1365
|
+ return -ENOMEM;
|
|
1366
|
+
|
|
1367
|
+ /* Fetch formatted value */
|
|
1368
|
+ check_len = fetchf_named_setting ( name, NULL, 0, *data,
|
|
1369
|
+ ( len + 1 /* NUL */ ) );
|
|
1370
|
+ assert ( check_len == len );
|
|
1371
|
+ return len;
|
|
1372
|
+}
|
|
1373
|
+
|
1335
|
1374
|
/******************************************************************************
|
1336
|
1375
|
*
|
1337
|
1376
|
* Setting types
|