6 struct keyval
*keyvals_dup(const struct keyval
*keyvals
)
11 for (i
= 0; keyvals
[i
].key
; i
++)
13 c
= xnew(struct keyval
, i
+ 1);
14 for (i
= 0; keyvals
[i
].key
; i
++) {
15 c
[i
].key
= xstrdup(keyvals
[i
].key
);
16 c
[i
].val
= xstrdup(keyvals
[i
].val
);
23 void keyvals_free(struct keyval
*keyvals
)
27 for (i
= 0; keyvals
[i
].key
; i
++) {
34 const char *keyvals_get_val(const struct keyval
*keyvals
, const char *key
)
38 for (i
= 0; keyvals
[i
].key
; i
++) {
39 if (strcasecmp(keyvals
[i
].key
, key
) == 0)
40 return keyvals
[i
].val
;
45 void keyvals_add(struct growing_keyvals
*c
, const char *key
, char *val
)
51 c
->keyvals
= xrenew(struct keyval
, c
->keyvals
, n
);
55 c
->keyvals
[c
->count
].key
= xstrdup(key
);
56 c
->keyvals
[c
->count
].val
= val
;
60 void keyvals_terminate(struct growing_keyvals
*c
)
62 int alloc
= c
->count
+ 1;
64 if (alloc
> c
->alloc
) {
65 c
->keyvals
= xrenew(struct keyval
, c
->keyvals
, alloc
);
68 c
->keyvals
[c
->count
].key
= NULL
;
69 c
->keyvals
[c
->count
].val
= NULL
;