stringlist.c (108868) | stringlist.c (109508) |
---|---|
1/* 2 * Copyright (c) 1994 Christos Zoulas 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 19 unchanged lines hidden (view full) --- 28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29 * SUCH DAMAGE. 30 */ 31 32#if defined(LIBC_SCCS) && !defined(lint) 33static char *rcsid = "$NetBSD: stringlist.c,v 1.2 1997/01/17 07:26:20 lukem Exp $"; 34#endif /* LIBC_SCCS and not lint */ 35#include <sys/cdefs.h> | 1/* 2 * Copyright (c) 1994 Christos Zoulas 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 19 unchanged lines hidden (view full) --- 28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29 * SUCH DAMAGE. 30 */ 31 32#if defined(LIBC_SCCS) && !defined(lint) 33static char *rcsid = "$NetBSD: stringlist.c,v 1.2 1997/01/17 07:26:20 lukem Exp $"; 34#endif /* LIBC_SCCS and not lint */ 35#include <sys/cdefs.h> |
36__FBSDID("$FreeBSD: head/lib/libc/gen/stringlist.c 108868 2003-01-07 06:55:58Z tjr $"); | 36__FBSDID("$FreeBSD: head/lib/libc/gen/stringlist.c 109508 2003-01-19 01:16:01Z obrien $"); |
37 38#include "namespace.h" 39#include <stdio.h> 40#include <string.h> 41#include <err.h> 42#include <stdlib.h> 43#include <stringlist.h> 44#include "un-namespace.h" 45 46#define _SL_CHUNKSIZE 20 47 48/* 49 * sl_init(): Initialize a string list 50 */ 51StringList * 52sl_init() 53{ | 37 38#include "namespace.h" 39#include <stdio.h> 40#include <string.h> 41#include <err.h> 42#include <stdlib.h> 43#include <stringlist.h> 44#include "un-namespace.h" 45 46#define _SL_CHUNKSIZE 20 47 48/* 49 * sl_init(): Initialize a string list 50 */ 51StringList * 52sl_init() 53{ |
54 StringList *sl = malloc(sizeof(StringList)); | 54 StringList *sl; 55 56 sl = malloc(sizeof(StringList)); |
55 if (sl == NULL) 56 _err(1, "stringlist: %m"); 57 58 sl->sl_cur = 0; 59 sl->sl_max = _SL_CHUNKSIZE; 60 sl->sl_str = malloc(sl->sl_max * sizeof(char *)); 61 if (sl->sl_str == NULL) 62 _err(1, "stringlist: %m"); 63 return sl; 64} 65 66 67/* 68 * sl_add(): Add an item to the string list 69 */ | 57 if (sl == NULL) 58 _err(1, "stringlist: %m"); 59 60 sl->sl_cur = 0; 61 sl->sl_max = _SL_CHUNKSIZE; 62 sl->sl_str = malloc(sl->sl_max * sizeof(char *)); 63 if (sl->sl_str == NULL) 64 _err(1, "stringlist: %m"); 65 return sl; 66} 67 68 69/* 70 * sl_add(): Add an item to the string list 71 */ |
70void | 72int |
71sl_add(sl, name) 72 StringList *sl; 73 char *name; 74{ 75 if (sl->sl_cur == sl->sl_max - 1) { 76 sl->sl_max += _SL_CHUNKSIZE; 77 sl->sl_str = reallocf(sl->sl_str, sl->sl_max * sizeof(char *)); 78 if (sl->sl_str == NULL) | 73sl_add(sl, name) 74 StringList *sl; 75 char *name; 76{ 77 if (sl->sl_cur == sl->sl_max - 1) { 78 sl->sl_max += _SL_CHUNKSIZE; 79 sl->sl_str = reallocf(sl->sl_str, sl->sl_max * sizeof(char *)); 80 if (sl->sl_str == NULL) |
79 _err(1, "stringlist: %m"); | 81 return (-1); |
80 } 81 sl->sl_str[sl->sl_cur++] = name; | 82 } 83 sl->sl_str[sl->sl_cur++] = name; |
84 return (0); |
|
82} 83 84 85/* 86 * sl_free(): Free a stringlist 87 */ 88void 89sl_free(sl, all) --- 33 unchanged lines hidden --- | 85} 86 87 88/* 89 * sl_free(): Free a stringlist 90 */ 91void 92sl_free(sl, all) --- 33 unchanged lines hidden --- |