MCPcopy Create free account
hub / github.com/F-Stack/f-stack / nvpair_create_string_array

Function nvpair_create_string_array

freebsd/contrib/libnv/bsd_nvpair.c:1378–1423  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1376}
1377
1378nvpair_t *
1379nvpair_create_string_array(const char *name, const char * const *value,
1380 size_t nitems)
1381{
1382 nvpair_t *nvp;
1383 unsigned int ii;
1384 size_t datasize, size;
1385 char **data;
1386
1387 if (value == NULL || nitems == 0) {
1388 ERRNO_SET(EINVAL);
1389 return (NULL);
1390 }
1391
1392 nvp = NULL;
1393 datasize = 0;
1394 data = nv_malloc(sizeof(value[0]) * nitems);
1395 if (data == NULL)
1396 return (NULL);
1397
1398 for (ii = 0; ii < nitems; ii++) {
1399 if (value[ii] == NULL) {
1400 ERRNO_SET(EINVAL);
1401 goto fail;
1402 }
1403
1404 size = strlen(value[ii]) + 1;
1405 datasize += size;
1406 data[ii] = nv_strdup(value[ii]);
1407 if (data[ii] == NULL)
1408 goto fail;
1409 }
1410 nvp = nvpair_allocv(name, NV_TYPE_STRING_ARRAY,
1411 (uint64_t)(uintptr_t)data, datasize, nitems);
1412
1413fail:
1414 if (nvp == NULL) {
1415 ERRNO_SAVE();
1416 for (; ii > 0; ii--)
1417 nv_free(data[ii - 1]);
1418 nv_free(data);
1419 ERRNO_RESTORE();
1420 }
1421
1422 return (nvp);
1423}
1424
1425nvpair_t *
1426nvpair_create_nvlist_array(const char *name, const nvlist_t * const *value,

Callers 1

nvpair_cloneFunction · 0.85

Calls 1

nvpair_allocvFunction · 0.85

Tested by

no test coverage detected