version 1.1.1.1, 2015/05/20 20:55:04 |
version 1.4, 2015/05/20 23:43:03 |
|
|
|
/* $Id$ */ |
/* |
/* |
* Copyright (c) 1994 Christos Zoulas |
* Copyright (c) 1994 Christos Zoulas <christos@netbsd.org> |
* All rights reserved. |
* All rights reserved. |
* |
* |
* Redistribution and use in source and binary forms, with or without |
* Redistribution and use in source and binary forms, with or without |
|
|
* 2. Redistributions in binary form must reproduce the above copyright |
* 2. Redistributions in binary form must reproduce the above copyright |
* notice, this list of conditions and the following disclaimer in the |
* notice, this list of conditions and the following disclaimer in the |
* documentation and/or other materials provided with the distribution. |
* documentation and/or other materials provided with the distribution. |
* 4. The name of the author may not be used to endorse or promote products |
|
* derived from this software without specific prior written permission. |
|
* |
* |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS |
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
|
|
* SUCH DAMAGE. |
* SUCH DAMAGE. |
*/ |
*/ |
|
|
#if defined(LIBC_SCCS) && !defined(lint) |
|
static char *rcsid = "$NetBSD: stringlist.c,v 1.2 1997/01/17 07:26:20 lukem Exp $"; |
|
#endif /* LIBC_SCCS and not lint */ |
|
#include <sys/cdefs.h> |
|
__FBSDID("$FreeBSD$"); |
|
|
|
#include "namespace.h" |
|
#include <stdio.h> |
|
#include <string.h> |
|
#include <err.h> |
#include <err.h> |
#include <stdlib.h> |
#include <stdlib.h> |
#include <stringlist.h> |
#include <string.h> |
#include "un-namespace.h" |
#include "compat_stringlist.h" |
|
|
#define _SL_CHUNKSIZE 20 |
#define _SL_CHUNKSIZE 20 |
|
|
|
|
|
|
sl = malloc(sizeof(StringList)); |
sl = malloc(sizeof(StringList)); |
if (sl == NULL) |
if (sl == NULL) |
_err(1, "stringlist: %m"); |
err(1, "stringlist"); |
|
|
sl->sl_cur = 0; |
sl->sl_cur = 0; |
sl->sl_max = _SL_CHUNKSIZE; |
sl->sl_max = _SL_CHUNKSIZE; |
sl->sl_str = malloc(sl->sl_max * sizeof(char *)); |
sl->sl_str = reallocarray(NULL, sl->sl_max, sizeof(char *)); |
if (sl->sl_str == NULL) |
if (sl->sl_str == NULL) |
_err(1, "stringlist: %m"); |
err(1, "stringlist"); |
return sl; |
return sl; |
} |
} |
|
|
Line 71 sl_add(StringList *sl, char *name) |
|
Line 61 sl_add(StringList *sl, char *name) |
|
{ |
{ |
if (sl->sl_cur == sl->sl_max - 1) { |
if (sl->sl_cur == sl->sl_max - 1) { |
sl->sl_max += _SL_CHUNKSIZE; |
sl->sl_max += _SL_CHUNKSIZE; |
sl->sl_str = reallocf(sl->sl_str, sl->sl_max * sizeof(char *)); |
sl->sl_str = reallocarray(sl->sl_str, |
|
sl->sl_max, sizeof(char *)); |
if (sl->sl_str == NULL) |
if (sl->sl_str == NULL) |
return (-1); |
return (-1); |
} |
} |