+++ /dev/null
-/* $NetBSD: stringlist.c,v 1.13 2008/04/28 20:22:59 martin Exp $\r
-\r
- * Copyright (c) 1994, 1999 The NetBSD Foundation, Inc.\r
- * All rights reserved.\r
- *\r
- * This code is derived from software contributed to The NetBSD Foundation\r
- * by Christos Zoulas.\r
- *\r
- * Redistribution and use in source and binary forms, with or without\r
- * modification, are permitted provided that the following conditions\r
- * are met:\r
- * 1. Redistributions of source code must retain the above copyright\r
- * notice, this list of conditions and the following disclaimer.\r
- * 2. Redistributions in binary form must reproduce the above copyright\r
- * notice, this list of conditions and the following disclaimer in the\r
- * documentation and/or other materials provided with the distribution.\r
- *\r
- * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS\r
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED\r
- * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\r
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS\r
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\r
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\r
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\r
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
- * POSSIBILITY OF SUCH DAMAGE.\r
- */\r
-#if defined(_MSC_VER) /* Handle Microsoft VC++ compiler specifics. */\r
- #pragma warning ( disable : 4018 )\r
-#endif\r
-\r
-#include <sys/cdefs.h>\r
-#if defined(LIBC_SCCS) && !defined(lint)\r
-__RCSID("$NetBSD: stringlist.c,v 1.13 2008/04/28 20:22:59 martin Exp $");\r
-#endif /* LIBC_SCCS and not lint */\r
-\r
-#include <assert.h>\r
-#include <stdio.h>\r
-#include <stdlib.h>\r
-#include <string.h>\r
-#include <stringlist.h>\r
-\r
-#ifdef __weak_alias\r
-__weak_alias(sl_add,_sl_add)\r
-__weak_alias(sl_find,_sl_find)\r
-__weak_alias(sl_free,_sl_free)\r
-__weak_alias(sl_init,_sl_init)\r
-__weak_alias(sl_delete,_sl_delete)\r
-#endif\r
-\r
-#define _SL_CHUNKSIZE 20\r
-\r
-/*\r
- * sl_init(): Initialize a string list\r
- */\r
-StringList *\r
-sl_init(void)\r
-{\r
- StringList *sl;\r
-\r
- sl = malloc(sizeof(StringList));\r
- if (sl == NULL)\r
- return NULL;\r
-\r
- sl->sl_cur = 0;\r
- sl->sl_max = _SL_CHUNKSIZE;\r
- sl->sl_str = malloc(sl->sl_max * sizeof(char *));\r
- if (sl->sl_str == NULL) {\r
- free(sl);\r
- sl = NULL;\r
- }\r
- return sl;\r
-}\r
-\r
-\r
-/*\r
- * sl_add(): Add an item to the string list\r
- */\r
-int\r
-sl_add(StringList *sl, char *name)\r
-{\r
-\r
- _DIAGASSERT(sl != NULL);\r
-\r
- if (sl->sl_cur == sl->sl_max - 1) {\r
- char **new;\r
-\r
- new = realloc(sl->sl_str,\r
- (sl->sl_max + _SL_CHUNKSIZE) * sizeof(char *));\r
- if (new == NULL)\r
- return -1;\r
- sl->sl_max += _SL_CHUNKSIZE;\r
- sl->sl_str = new;\r
- }\r
- sl->sl_str[sl->sl_cur++] = name;\r
- return 0;\r
-}\r
-\r
-\r
-/*\r
- * sl_free(): Free a stringlist\r
- */\r
-void\r
-sl_free(StringList *sl, int all)\r
-{\r
- size_t i;\r
-\r
- if (sl == NULL)\r
- return;\r
- if (sl->sl_str) {\r
- if (all)\r
- for (i = 0; i < sl->sl_cur; i++)\r
- free(sl->sl_str[i]);\r
- free(sl->sl_str);\r
- }\r
- free(sl);\r
-}\r
-\r
-\r
-/*\r
- * sl_find(): Find a name in the string list\r
- */\r
-char *\r
-sl_find(StringList *sl, const char *name)\r
-{\r
- size_t i;\r
-\r
- _DIAGASSERT(sl != NULL);\r
-\r
- for (i = 0; i < sl->sl_cur; i++)\r
- if (strcmp(sl->sl_str[i], name) == 0)\r
- return sl->sl_str[i];\r
-\r
- return NULL;\r
-}\r
-\r
-int\r
-sl_delete(StringList *sl, const char *name, int all)\r
-{\r
- size_t i, j;\r
-\r
- for (i = 0; i < sl->sl_cur; i++)\r
- if (strcmp(sl->sl_str[i], name) == 0) {\r
- if (all)\r
- free(sl->sl_str[i]);\r
- for (j = i + 1; j < sl->sl_cur; j++)\r
- sl->sl_str[j - 1] = sl->sl_str[j];\r
- sl->sl_str[--sl->sl_cur] = NULL;\r
- return 0;\r
- }\r
- return -1;\r
-}\r
-\r