17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5a126dc1aSTony Nguyen * Common Development and Distribution License (the "License"). 6a126dc1aSTony Nguyen * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 217c478bd9Sstevel@tonic-gate /* 22*4e1c7343SJan Friedel * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved. 237c478bd9Sstevel@tonic-gate */ 247c478bd9Sstevel@tonic-gate 257c478bd9Sstevel@tonic-gate 267c478bd9Sstevel@tonic-gate #include <stdio.h> 277c478bd9Sstevel@tonic-gate #include <stdlib.h> 287c478bd9Sstevel@tonic-gate #include <strings.h> 297c478bd9Sstevel@tonic-gate #include <secdb.h> 307c478bd9Sstevel@tonic-gate #include <ctype.h> 317c478bd9Sstevel@tonic-gate 327c478bd9Sstevel@tonic-gate /* From libnsl */ 337c478bd9Sstevel@tonic-gate extern char *_strdup_null(char *); 347c478bd9Sstevel@tonic-gate extern char *_strtok_escape(char *, char *, char **); 357c478bd9Sstevel@tonic-gate extern char *_strpbrk_escape(char *, char *); 367c478bd9Sstevel@tonic-gate extern char *_unescape(char *, char *); 377c478bd9Sstevel@tonic-gate 387c478bd9Sstevel@tonic-gate char *_do_unescape(char *); 397c478bd9Sstevel@tonic-gate 407c478bd9Sstevel@tonic-gate 417c478bd9Sstevel@tonic-gate /* 427c478bd9Sstevel@tonic-gate * kva_match(): Given a key-value array and a key, return a pointer to the 437c478bd9Sstevel@tonic-gate * value that matches the key. 447c478bd9Sstevel@tonic-gate */ 457c478bd9Sstevel@tonic-gate char * 467c478bd9Sstevel@tonic-gate kva_match(kva_t *kva, char *key) 477c478bd9Sstevel@tonic-gate { 487c478bd9Sstevel@tonic-gate int i; 497c478bd9Sstevel@tonic-gate kv_t *data; 507c478bd9Sstevel@tonic-gate 517c478bd9Sstevel@tonic-gate if (kva == NULL || key == NULL) { 527c478bd9Sstevel@tonic-gate return ((char *)NULL); 537c478bd9Sstevel@tonic-gate } 547c478bd9Sstevel@tonic-gate data = kva->data; 557c478bd9Sstevel@tonic-gate for (i = 0; i < kva->length; i++) { 567c478bd9Sstevel@tonic-gate if (strcmp(data[i].key, key) == 0) { 577c478bd9Sstevel@tonic-gate return (data[i].value); 587c478bd9Sstevel@tonic-gate } 597c478bd9Sstevel@tonic-gate } 607c478bd9Sstevel@tonic-gate 617c478bd9Sstevel@tonic-gate return ((char *)NULL); 627c478bd9Sstevel@tonic-gate } 637c478bd9Sstevel@tonic-gate 647c478bd9Sstevel@tonic-gate /* 657c478bd9Sstevel@tonic-gate * _kva_free(): Free up memory. 667c478bd9Sstevel@tonic-gate */ 677c478bd9Sstevel@tonic-gate void 687c478bd9Sstevel@tonic-gate _kva_free(kva_t *kva) 697c478bd9Sstevel@tonic-gate { 707c478bd9Sstevel@tonic-gate int i; 717c478bd9Sstevel@tonic-gate kv_t *data; 727c478bd9Sstevel@tonic-gate 737c478bd9Sstevel@tonic-gate if (kva == NULL) { 747c478bd9Sstevel@tonic-gate return; 757c478bd9Sstevel@tonic-gate } 767c478bd9Sstevel@tonic-gate data = kva->data; 777c478bd9Sstevel@tonic-gate for (i = 0; i < kva->length; i++) { 787c478bd9Sstevel@tonic-gate if (data[i].key != NULL) { 797c478bd9Sstevel@tonic-gate free(data[i].key); 807c478bd9Sstevel@tonic-gate data[i].key = NULL; 817c478bd9Sstevel@tonic-gate } 827c478bd9Sstevel@tonic-gate if (data[i].value != NULL) { 837c478bd9Sstevel@tonic-gate free(data[i].value); 847c478bd9Sstevel@tonic-gate data[i].value = NULL; 857c478bd9Sstevel@tonic-gate } 867c478bd9Sstevel@tonic-gate } 877c478bd9Sstevel@tonic-gate free(kva->data); 887c478bd9Sstevel@tonic-gate free(kva); 897c478bd9Sstevel@tonic-gate } 907c478bd9Sstevel@tonic-gate 917c478bd9Sstevel@tonic-gate /* 927c478bd9Sstevel@tonic-gate * new_kva(): Allocate a key-value array. 937c478bd9Sstevel@tonic-gate */ 947c478bd9Sstevel@tonic-gate kva_t * 957c478bd9Sstevel@tonic-gate _new_kva(int size) 967c478bd9Sstevel@tonic-gate { 977c478bd9Sstevel@tonic-gate kva_t *new_kva; 987c478bd9Sstevel@tonic-gate 997c478bd9Sstevel@tonic-gate if ((new_kva = (kva_t *)calloc(1, sizeof (kva_t))) == NULL) { 1007c478bd9Sstevel@tonic-gate return ((kva_t *)NULL); 1017c478bd9Sstevel@tonic-gate } 1027c478bd9Sstevel@tonic-gate if ((new_kva->data = (kv_t *)calloc(1, (size*sizeof (kv_t)))) == NULL) { 1037c478bd9Sstevel@tonic-gate free(new_kva); 1047c478bd9Sstevel@tonic-gate return ((kva_t *)NULL); 1057c478bd9Sstevel@tonic-gate } 1067c478bd9Sstevel@tonic-gate 1077c478bd9Sstevel@tonic-gate return (new_kva); 1087c478bd9Sstevel@tonic-gate } 1097c478bd9Sstevel@tonic-gate 1107c478bd9Sstevel@tonic-gate /* 1117c478bd9Sstevel@tonic-gate * _str2kva(): Given a string (s) of key-value pairs, separated by delimeter 1127c478bd9Sstevel@tonic-gate * (del), place the values into the key value array (nkva). 1137c478bd9Sstevel@tonic-gate */ 1147c478bd9Sstevel@tonic-gate kva_t * 1157c478bd9Sstevel@tonic-gate _str2kva(char *s, char *ass, char *del) 1167c478bd9Sstevel@tonic-gate { 1177c478bd9Sstevel@tonic-gate int n = 0; 1187c478bd9Sstevel@tonic-gate int m; 1197c478bd9Sstevel@tonic-gate int size = KV_ADD_KEYS; 1207c478bd9Sstevel@tonic-gate char *buf; 1217c478bd9Sstevel@tonic-gate char *p; 1227c478bd9Sstevel@tonic-gate char *pair; 1237c478bd9Sstevel@tonic-gate char *key; 1247c478bd9Sstevel@tonic-gate char *last_pair; 1257c478bd9Sstevel@tonic-gate char *last_key; 1267c478bd9Sstevel@tonic-gate kv_t *data; 1277c478bd9Sstevel@tonic-gate kva_t *nkva; 1287c478bd9Sstevel@tonic-gate 1297c478bd9Sstevel@tonic-gate if (s == NULL || 1307c478bd9Sstevel@tonic-gate ass == NULL || 1317c478bd9Sstevel@tonic-gate del == NULL || 1327c478bd9Sstevel@tonic-gate *s == '\0' || 1337c478bd9Sstevel@tonic-gate *s == '\n' || 1347c478bd9Sstevel@tonic-gate (strlen(s) <= 1)) { 1357c478bd9Sstevel@tonic-gate return ((kva_t *)NULL); 1367c478bd9Sstevel@tonic-gate } 1377c478bd9Sstevel@tonic-gate p = s; 1387c478bd9Sstevel@tonic-gate while ((p = _strpbrk_escape(p, ass)) != NULL) { 1397c478bd9Sstevel@tonic-gate n++; 1407c478bd9Sstevel@tonic-gate p++; 1417c478bd9Sstevel@tonic-gate } 1427c478bd9Sstevel@tonic-gate if (n > size) { 1437c478bd9Sstevel@tonic-gate m = n/size; 1447c478bd9Sstevel@tonic-gate if (n%size) { 1457c478bd9Sstevel@tonic-gate ++m; 1467c478bd9Sstevel@tonic-gate } 1477c478bd9Sstevel@tonic-gate size = m * KV_ADD_KEYS; 1487c478bd9Sstevel@tonic-gate } 1497c478bd9Sstevel@tonic-gate if ((nkva = _new_kva(size)) == NULL) { 1507c478bd9Sstevel@tonic-gate return ((kva_t *)NULL); 1517c478bd9Sstevel@tonic-gate } 1527c478bd9Sstevel@tonic-gate data = nkva->data; 1537c478bd9Sstevel@tonic-gate nkva->length = 0; 1547c478bd9Sstevel@tonic-gate if ((buf = strdup(s)) == NULL) { 1557c478bd9Sstevel@tonic-gate return ((kva_t *)NULL); 1567c478bd9Sstevel@tonic-gate } 1577c478bd9Sstevel@tonic-gate pair = _strtok_escape(buf, del, &last_pair); 1587c478bd9Sstevel@tonic-gate do { 1597c478bd9Sstevel@tonic-gate key = _strtok_escape(pair, ass, &last_key); 1607c478bd9Sstevel@tonic-gate if (key != NULL) { 1617c478bd9Sstevel@tonic-gate data[nkva->length].key = _do_unescape(key); 1627c478bd9Sstevel@tonic-gate data[nkva->length].value = _do_unescape(last_key); 1637c478bd9Sstevel@tonic-gate nkva->length++; 1647c478bd9Sstevel@tonic-gate } 1657c478bd9Sstevel@tonic-gate } while ((pair = _strtok_escape(NULL, del, &last_pair)) != NULL); 1667c478bd9Sstevel@tonic-gate free(buf); 1677c478bd9Sstevel@tonic-gate return (nkva); 1687c478bd9Sstevel@tonic-gate } 1697c478bd9Sstevel@tonic-gate 1707c478bd9Sstevel@tonic-gate /* 1717c478bd9Sstevel@tonic-gate * _kva2str(): Given an array of key-value pairs, place them into a string 1727c478bd9Sstevel@tonic-gate * (buf). Use delimeter (del) to separate pairs. Use assignment character 1737c478bd9Sstevel@tonic-gate * (ass) to separate keys and values. 1747c478bd9Sstevel@tonic-gate * 1757c478bd9Sstevel@tonic-gate * Return Values: 0 Success 1 Buffer too small 2 Out of memory 1767c478bd9Sstevel@tonic-gate */ 1777c478bd9Sstevel@tonic-gate int 1787c478bd9Sstevel@tonic-gate _kva2str(kva_t *kva, char *buf, int buflen, char *ass, char *del) 1797c478bd9Sstevel@tonic-gate { 1807c478bd9Sstevel@tonic-gate int i; 1817c478bd9Sstevel@tonic-gate int length = 0; 1827c478bd9Sstevel@tonic-gate char *tmp; 1837c478bd9Sstevel@tonic-gate kv_t *data; 1847c478bd9Sstevel@tonic-gate 1857c478bd9Sstevel@tonic-gate if (kva == NULL) { 1867c478bd9Sstevel@tonic-gate return (0); 1877c478bd9Sstevel@tonic-gate } 1887c478bd9Sstevel@tonic-gate data = kva->data; 1897c478bd9Sstevel@tonic-gate for (i = 0; i < kva->length; i++) { 1907c478bd9Sstevel@tonic-gate if (data[i].value != NULL) { 1917c478bd9Sstevel@tonic-gate length += 2 + strlen(data[i].value); 1927c478bd9Sstevel@tonic-gate } 1937c478bd9Sstevel@tonic-gate } 1947c478bd9Sstevel@tonic-gate if (length > buflen) { 1957c478bd9Sstevel@tonic-gate return (1); 1967c478bd9Sstevel@tonic-gate } 1977c478bd9Sstevel@tonic-gate (void) memset(buf, 0, buflen); 1987c478bd9Sstevel@tonic-gate if ((tmp = (char *)malloc(buflen)) == NULL) { 1997c478bd9Sstevel@tonic-gate return (2); 2007c478bd9Sstevel@tonic-gate } 2017c478bd9Sstevel@tonic-gate for (i = 0; i < kva->length; i++) { 2027c478bd9Sstevel@tonic-gate if (data[i].value != NULL) { 2037c478bd9Sstevel@tonic-gate if (snprintf(tmp, buflen, "%s%s%s%s", 2047c478bd9Sstevel@tonic-gate data[i].key, ass, data[i].value, del) >= buflen) { 205*4e1c7343SJan Friedel free((void *)tmp); 2067c478bd9Sstevel@tonic-gate return (0); 2077c478bd9Sstevel@tonic-gate } 2087c478bd9Sstevel@tonic-gate (void) strcat(buf, tmp); 2097c478bd9Sstevel@tonic-gate } 2107c478bd9Sstevel@tonic-gate } 211*4e1c7343SJan Friedel free((void *)tmp); 2127c478bd9Sstevel@tonic-gate return (0); 2137c478bd9Sstevel@tonic-gate } 2147c478bd9Sstevel@tonic-gate 2157c478bd9Sstevel@tonic-gate int 2167c478bd9Sstevel@tonic-gate _insert2kva(kva_t *kva, char *key, char *value) 2177c478bd9Sstevel@tonic-gate { 2187c478bd9Sstevel@tonic-gate int i; 2197c478bd9Sstevel@tonic-gate kv_t *data; 2207c478bd9Sstevel@tonic-gate 2217c478bd9Sstevel@tonic-gate if (kva == NULL) { 2227c478bd9Sstevel@tonic-gate return (0); 2237c478bd9Sstevel@tonic-gate } 2247c478bd9Sstevel@tonic-gate data = kva->data; 2257c478bd9Sstevel@tonic-gate for (i = 0; i < kva->length; i++) { 2267c478bd9Sstevel@tonic-gate if (strcmp(data[i].key, key) == 0) { 2277c478bd9Sstevel@tonic-gate if (data[i].value != NULL) 2287c478bd9Sstevel@tonic-gate free(data[i].value); 2297c478bd9Sstevel@tonic-gate data[i].value = _strdup_null(value); 2307c478bd9Sstevel@tonic-gate return (0); 2317c478bd9Sstevel@tonic-gate } 2327c478bd9Sstevel@tonic-gate } 2337c478bd9Sstevel@tonic-gate return (1); 2347c478bd9Sstevel@tonic-gate } 2357c478bd9Sstevel@tonic-gate 2367c478bd9Sstevel@tonic-gate kva_t * 2377c478bd9Sstevel@tonic-gate _kva_dup(kva_t *old_kva) 2387c478bd9Sstevel@tonic-gate { 2397c478bd9Sstevel@tonic-gate int i; 2407c478bd9Sstevel@tonic-gate int size; 2417c478bd9Sstevel@tonic-gate kv_t *old_data; 2427c478bd9Sstevel@tonic-gate kv_t *new_data; 2437c478bd9Sstevel@tonic-gate kva_t *nkva = (kva_t *)NULL; 2447c478bd9Sstevel@tonic-gate 2457c478bd9Sstevel@tonic-gate if (old_kva == NULL) { 2467c478bd9Sstevel@tonic-gate return ((kva_t *)NULL); 2477c478bd9Sstevel@tonic-gate } 2487c478bd9Sstevel@tonic-gate old_data = old_kva->data; 2497c478bd9Sstevel@tonic-gate size = old_kva->length; 2507c478bd9Sstevel@tonic-gate if ((nkva = _new_kva(size)) == NULL) { 2517c478bd9Sstevel@tonic-gate return ((kva_t *)NULL); 2527c478bd9Sstevel@tonic-gate } 2537c478bd9Sstevel@tonic-gate new_data = nkva->data; 2547c478bd9Sstevel@tonic-gate nkva->length = old_kva->length; 255c94b466cSJan Friedel for (i = 0; i < nkva->length; i++) { 2567c478bd9Sstevel@tonic-gate new_data[i].key = _strdup_null(old_data[i].key); 2577c478bd9Sstevel@tonic-gate new_data[i].value = _strdup_null(old_data[i].value); 2587c478bd9Sstevel@tonic-gate } 2597c478bd9Sstevel@tonic-gate 2607c478bd9Sstevel@tonic-gate return (nkva); 2617c478bd9Sstevel@tonic-gate } 2627c478bd9Sstevel@tonic-gate 2637c478bd9Sstevel@tonic-gate static void 2647c478bd9Sstevel@tonic-gate strip_spaces(char **valuep) 2657c478bd9Sstevel@tonic-gate { 2667c478bd9Sstevel@tonic-gate char *p, *start; 2677c478bd9Sstevel@tonic-gate 2687c478bd9Sstevel@tonic-gate /* Find first non-white space character and return pointer to it */ 2697c478bd9Sstevel@tonic-gate for (p = *valuep; *p != '\0' && isspace((unsigned char)*p); p++) 2707c478bd9Sstevel@tonic-gate ; 2717c478bd9Sstevel@tonic-gate 2727c478bd9Sstevel@tonic-gate *valuep = start = p; 2737c478bd9Sstevel@tonic-gate 2747c478bd9Sstevel@tonic-gate if (*p == '\0') 2757c478bd9Sstevel@tonic-gate return; 2767c478bd9Sstevel@tonic-gate 2777c478bd9Sstevel@tonic-gate p = p + strlen(p) - 1; 2787c478bd9Sstevel@tonic-gate 2797c478bd9Sstevel@tonic-gate /* Remove trailing spaces */ 2807c478bd9Sstevel@tonic-gate while (p > start && isspace((unsigned char)*p)) 2817c478bd9Sstevel@tonic-gate p--; 2827c478bd9Sstevel@tonic-gate 2837c478bd9Sstevel@tonic-gate p[1] = '\0'; 2847c478bd9Sstevel@tonic-gate } 2857c478bd9Sstevel@tonic-gate 2867c478bd9Sstevel@tonic-gate char * 2877c478bd9Sstevel@tonic-gate _do_unescape(char *src) 2887c478bd9Sstevel@tonic-gate { 2897c478bd9Sstevel@tonic-gate char *tmp = NULL; 2907c478bd9Sstevel@tonic-gate char *dst = NULL; 2917c478bd9Sstevel@tonic-gate 2927c478bd9Sstevel@tonic-gate if (src == NULL) { 2937c478bd9Sstevel@tonic-gate dst = _strdup_null(src); 2947c478bd9Sstevel@tonic-gate } else { 2957c478bd9Sstevel@tonic-gate strip_spaces(&src); 2967c478bd9Sstevel@tonic-gate tmp = _unescape(src, "=;:,\\"); 2977c478bd9Sstevel@tonic-gate dst = (tmp == NULL) ? _strdup_null(src) : tmp; 2987c478bd9Sstevel@tonic-gate } 2997c478bd9Sstevel@tonic-gate 3007c478bd9Sstevel@tonic-gate return (dst); 3017c478bd9Sstevel@tonic-gate } 3027c478bd9Sstevel@tonic-gate 3037c478bd9Sstevel@tonic-gate 3047c478bd9Sstevel@tonic-gate /* 3057c478bd9Sstevel@tonic-gate * Some utilities for handling comma-separated lists. 3067c478bd9Sstevel@tonic-gate */ 3077c478bd9Sstevel@tonic-gate char * 3087c478bd9Sstevel@tonic-gate _argv_to_csl(char **strings) 3097c478bd9Sstevel@tonic-gate { 3107c478bd9Sstevel@tonic-gate int len = 0; 3117c478bd9Sstevel@tonic-gate int i = 0; 3127c478bd9Sstevel@tonic-gate char *newstr = (char *)NULL; 3137c478bd9Sstevel@tonic-gate 3147c478bd9Sstevel@tonic-gate if (strings == NULL) 3157c478bd9Sstevel@tonic-gate return ((char *)NULL); 3167c478bd9Sstevel@tonic-gate for (i = 0; strings[i] != NULL; i++) { 3177c478bd9Sstevel@tonic-gate len += strlen(strings[i]) + 1; 3187c478bd9Sstevel@tonic-gate } 319a126dc1aSTony Nguyen if ((len > 0) && ((newstr = (char *)malloc(len + 1)) != NULL)) { 3207c478bd9Sstevel@tonic-gate (void) memset(newstr, 0, len); 3217c478bd9Sstevel@tonic-gate for (i = 0; strings[i] != NULL; i++) { 3227c478bd9Sstevel@tonic-gate (void) strcat(newstr, strings[i]); 3237c478bd9Sstevel@tonic-gate (void) strcat(newstr, ","); 3247c478bd9Sstevel@tonic-gate } 3257c478bd9Sstevel@tonic-gate newstr[len-1] = NULL; 3267c478bd9Sstevel@tonic-gate return (newstr); 327a126dc1aSTony Nguyen } else 328a126dc1aSTony Nguyen return ((char *)NULL); 3297c478bd9Sstevel@tonic-gate } 3307c478bd9Sstevel@tonic-gate 3317c478bd9Sstevel@tonic-gate 3327c478bd9Sstevel@tonic-gate char ** 3337c478bd9Sstevel@tonic-gate _csl_to_argv(char *csl) 3347c478bd9Sstevel@tonic-gate { 3357c478bd9Sstevel@tonic-gate int len = 0; 3367c478bd9Sstevel@tonic-gate int ncommas = 0; 3377c478bd9Sstevel@tonic-gate int i = 0; 3387c478bd9Sstevel@tonic-gate char **spc = (char **)NULL; 3397c478bd9Sstevel@tonic-gate char *copy = (char *)NULL; 3407c478bd9Sstevel@tonic-gate char *pc; 3417c478bd9Sstevel@tonic-gate char *lasts = (char *)NULL; 3427c478bd9Sstevel@tonic-gate 3437c478bd9Sstevel@tonic-gate len = strlen(csl); 3447c478bd9Sstevel@tonic-gate for (i = 0; i < len; i++) { 3457c478bd9Sstevel@tonic-gate if (csl[i] == ',') 3467c478bd9Sstevel@tonic-gate ncommas++; 3477c478bd9Sstevel@tonic-gate } 3487c478bd9Sstevel@tonic-gate if ((spc = (char **)malloc((ncommas + 2) * sizeof (char *))) == NULL) { 3497c478bd9Sstevel@tonic-gate return ((char **)NULL); 3507c478bd9Sstevel@tonic-gate } 3517c478bd9Sstevel@tonic-gate copy = strdup(csl); 3527c478bd9Sstevel@tonic-gate for (pc = strtok_r(copy, ",", &lasts), i = 0; pc != NULL; 3537c478bd9Sstevel@tonic-gate pc = strtok_r(NULL, ",", &lasts), i++) { 3547c478bd9Sstevel@tonic-gate spc[i] = strdup(pc); 3557c478bd9Sstevel@tonic-gate } 3567c478bd9Sstevel@tonic-gate spc[i] = NULL; 3577c478bd9Sstevel@tonic-gate free(copy); 3587c478bd9Sstevel@tonic-gate return (spc); 3597c478bd9Sstevel@tonic-gate } 3607c478bd9Sstevel@tonic-gate 3617c478bd9Sstevel@tonic-gate 3627c478bd9Sstevel@tonic-gate void 3637c478bd9Sstevel@tonic-gate _free_argv(char **p_argv) 3647c478bd9Sstevel@tonic-gate { 3657c478bd9Sstevel@tonic-gate char **p_a; 3667c478bd9Sstevel@tonic-gate 3677c478bd9Sstevel@tonic-gate for (p_a = p_argv; *p_a != NULL; p_a++) 3687c478bd9Sstevel@tonic-gate free(*p_a); 3697c478bd9Sstevel@tonic-gate free(p_argv); 3707c478bd9Sstevel@tonic-gate } 3717c478bd9Sstevel@tonic-gate 3727c478bd9Sstevel@tonic-gate 3737c478bd9Sstevel@tonic-gate #ifdef DEBUG 3747c478bd9Sstevel@tonic-gate void 3757c478bd9Sstevel@tonic-gate print_kva(kva_t *kva) 3767c478bd9Sstevel@tonic-gate { 3777c478bd9Sstevel@tonic-gate int i; 3787c478bd9Sstevel@tonic-gate kv_t *data; 3797c478bd9Sstevel@tonic-gate 3807c478bd9Sstevel@tonic-gate if (kva == NULL) { 3817c478bd9Sstevel@tonic-gate printf(" (empty)\n"); 3827c478bd9Sstevel@tonic-gate return; 3837c478bd9Sstevel@tonic-gate } 3847c478bd9Sstevel@tonic-gate data = kva->data; 3857c478bd9Sstevel@tonic-gate for (i = 0; i < kva->length; i++) { 3867c478bd9Sstevel@tonic-gate printf(" %s = %s\n", data[i].key, data[i].value); 3877c478bd9Sstevel@tonic-gate } 3887c478bd9Sstevel@tonic-gate } 3897c478bd9Sstevel@tonic-gate #endif /* DEBUG */ 390