Lines Matching defs:?*

0 #include "config.h"
3 #if HAVE_STRINGLIST
5 int dummy;
7 #else
9 /* $Id: compat_stringlist.c,v 1.6 2015/11/07 14:22:29 schwarze Exp $ */
11 * Copyright (c) 1994 Christos Zoulas <christos@netbsd.org>
12 * All rights reserved.
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions
16 * are met:
17 * 1. Redistributions of source code must retain the above copyright
18 * notice, this list of conditions and the following disclaimer.
19 * 2. Redistributions in binary form must reproduce the above copyright
20 * notice, this list of conditions and the following disclaimer in the
21 * documentation and/or other materials provided with the distribution.
23 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
24 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
27 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * SUCH DAMAGE.
36 #if HAVE_ERR
37 #include <err.h>
38 #endif
39 #include <stdlib.h>
40 #include <string.h>
41 #include "compat_stringlist.h"
43 #define _SL_CHUNKSIZE 20
46 * sl_init(): Initialize a string list
48 StringList *
49 sl_init(void)
51 StringList *sl;
53 sl = malloc(sizeof(StringList));
54 if (sl == NULL)
55 err(1, "stringlist");
57 sl->sl_cur = 0;
58 sl->sl_max = _SL_CHUNKSIZE;
59 sl->sl_str = reallocarray(NULL, sl->sl_max, sizeof(char *));
60 if (sl->sl_str == NULL)
61 err(1, "stringlist");
62 return sl;
67 * sl_add(): Add an item to the string list
69 int
70 sl_add(StringList *sl, char *name)
72 if (sl->sl_cur == sl->sl_max - 1) {
73 sl->sl_max += _SL_CHUNKSIZE;
74 sl->sl_str = reallocarray(sl->sl_str,
75 sl->sl_max, sizeof(char *));
76 if (sl->sl_str == NULL)
77 return (-1);
79 sl->sl_str[sl->sl_cur++] = name;
80 return (0);
85 * sl_free(): Free a stringlist
87 void
88 sl_free(StringList *sl, int all)
90 size_t i;
92 if (sl == NULL)
93 return;
94 if (sl->sl_str) {
95 if (all)
96 for (i = 0; i < sl->sl_cur; i++)
97 free(sl->sl_str[i]);
98 free(sl->sl_str);
100 free(sl);
105 * sl_find(): Find a name in the string list
107 char *
108 sl_find(StringList *sl, const char *name)
110 size_t i;
112 for (i = 0; i < sl->sl_cur; i++)
113 if (strcmp(sl->sl_str[i], name) == 0)
114 return sl->sl_str[i];
116 return NULL;
119 #endif