1608 static int
1609 nvlist_lookup_nvpair_ei_sep(nvlist_t *nvl, const char *name, const char sep,
1610 nvpair_t **ret, int *ip, char **ep)
1611 {
1612 nvpair_t *nvp;
1613 const char *np;
1614 char *sepp;
1615 char *idxp, *idxep;
1616 nvlist_t **nva;
1617 long idx;
1618 int n;
1619
1620 if (ip)
1621 *ip = -1; /* not indexed */
1622 if (ep)
1623 *ep = NULL;
1624
1625 if ((nvl == NULL) || (name == NULL))
1626 return (EINVAL);
1627
1628 /* step through components of name */
1629 for (np = name; np && *np; np = sepp) {
1630 /* ensure unique names */
1631 if (!(nvl->nvl_nvflag & NV_UNIQUE_NAME))
1632 return (ENOTSUP);
1633
1634 /* skip white space */
1635 skip_whitespace(np);
1636 if (*np == 0)
1637 break;
1638
1639 /* set 'sepp' to end of current component 'np' */
1640 if (sep)
1641 sepp = strchr(np, sep);
1642 else
1643 sepp = NULL;
1644
1645 /* find start of next "[ index ]..." */
1646 idxp = strchr(np, '[');
1647
2365 return (EINVAL);
2366
2367 if (*bufp != NULL)
2368 return (nvlist_common(nvl, *bufp, buflen, encoding,
2369 NVS_OP_ENCODE));
2370
2371 /*
2372 * Here is a difficult situation:
2373 * 1. The nvlist has fixed allocator properties.
2374 * All other nvlist routines (like nvlist_add_*, ...) use
2375 * these properties.
2376 * 2. When using nvlist_pack() the user can specify his own
2377 * allocator properties (e.g. by using KM_NOSLEEP).
2378 *
2379 * We use the user specified properties (2). A clearer solution
2380 * will be to remove the kmflag from nvlist_pack(), but we will
2381 * not change the interface.
2382 */
2383 nv_priv_init(&nvpriv, nva, 0);
2384
2385 if (err = nvlist_size(nvl, &alloc_size, encoding))
2386 return (err);
2387
2388 if ((buf = nv_mem_zalloc(&nvpriv, alloc_size)) == NULL)
2389 return (ENOMEM);
2390
2391 if ((err = nvlist_common(nvl, buf, &alloc_size, encoding,
2392 NVS_OP_ENCODE)) != 0) {
2393 nv_mem_free(&nvpriv, buf, alloc_size);
2394 } else {
2395 *buflen = alloc_size;
2396 *bufp = buf;
2397 }
2398
2399 return (err);
2400 }
2401
2402 /*
2403 * Unpack buf into an nvlist_t
2404 */
2405 /*ARGSUSED1*/
|
1608 static int
1609 nvlist_lookup_nvpair_ei_sep(nvlist_t *nvl, const char *name, const char sep,
1610 nvpair_t **ret, int *ip, char **ep)
1611 {
1612 nvpair_t *nvp;
1613 const char *np;
1614 char *sepp;
1615 char *idxp, *idxep;
1616 nvlist_t **nva;
1617 long idx;
1618 int n;
1619
1620 if (ip)
1621 *ip = -1; /* not indexed */
1622 if (ep)
1623 *ep = NULL;
1624
1625 if ((nvl == NULL) || (name == NULL))
1626 return (EINVAL);
1627
1628 sepp = NULL;
1629 idx = 0;
1630 /* step through components of name */
1631 for (np = name; np && *np; np = sepp) {
1632 /* ensure unique names */
1633 if (!(nvl->nvl_nvflag & NV_UNIQUE_NAME))
1634 return (ENOTSUP);
1635
1636 /* skip white space */
1637 skip_whitespace(np);
1638 if (*np == 0)
1639 break;
1640
1641 /* set 'sepp' to end of current component 'np' */
1642 if (sep)
1643 sepp = strchr(np, sep);
1644 else
1645 sepp = NULL;
1646
1647 /* find start of next "[ index ]..." */
1648 idxp = strchr(np, '[');
1649
2367 return (EINVAL);
2368
2369 if (*bufp != NULL)
2370 return (nvlist_common(nvl, *bufp, buflen, encoding,
2371 NVS_OP_ENCODE));
2372
2373 /*
2374 * Here is a difficult situation:
2375 * 1. The nvlist has fixed allocator properties.
2376 * All other nvlist routines (like nvlist_add_*, ...) use
2377 * these properties.
2378 * 2. When using nvlist_pack() the user can specify his own
2379 * allocator properties (e.g. by using KM_NOSLEEP).
2380 *
2381 * We use the user specified properties (2). A clearer solution
2382 * will be to remove the kmflag from nvlist_pack(), but we will
2383 * not change the interface.
2384 */
2385 nv_priv_init(&nvpriv, nva, 0);
2386
2387 if ((err = nvlist_size(nvl, &alloc_size, encoding)))
2388 return (err);
2389
2390 if ((buf = nv_mem_zalloc(&nvpriv, alloc_size)) == NULL)
2391 return (ENOMEM);
2392
2393 if ((err = nvlist_common(nvl, buf, &alloc_size, encoding,
2394 NVS_OP_ENCODE)) != 0) {
2395 nv_mem_free(&nvpriv, buf, alloc_size);
2396 } else {
2397 *buflen = alloc_size;
2398 *bufp = buf;
2399 }
2400
2401 return (err);
2402 }
2403
2404 /*
2405 * Unpack buf into an nvlist_t
2406 */
2407 /*ARGSUSED1*/
|