2 Add a string to a list of strings.
4 Copyright (C) 1992 Ian Lance Taylor
6 This file is part of the Taylor UUCP uuconf library.
8 This library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Library General Public License
10 as published by the Free Software Foundation; either version 2 of
11 the License, or (at your option) any later version.
13 This library is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Library General Public License for more details.
18 You should have received a copy of the GNU Library General Public
19 License along with this library; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 The author of the program may be contacted at ian@airs.com or
23 c/o Cygnus Support, 48 Grove Street, Somerville, MA 02144.
29 const char _uuconf_addstr_rcsid[] = "$FreeBSD$";
34 /* When setting system information, we need to be able to distinguish
35 between a value that is not set and a value that has been set to
36 NULL. We do this by initializing the value to point to the
37 variable _uuconf_unset, and then correcting it in the function
38 _uuconf_isystem_basic_default. This variable is declared in this
39 file because some linkers will apparently not pull in an object
40 file which merely declarates a variable. This functions happens to
41 be pulled in by almost everything. */
45 /* Add a string to a list of strings. The list is maintained as an
46 array of elements ending in NULL. The total number of available
47 slots is always a multiple of CSLOTS, so by counting the current
48 number of elements we can tell whether a new slot is needed. If
49 the fcopy argument is TRUE, the new string is duplicated into
50 memory. If the fcheck argument is TRUE, this does not add a string
51 that is already in the list. The pblock argument may be used to do
52 the allocations within a memory block. This returns a standard
58 _uuconf_iadd_string (qglobal, zadd, fcopy, fcheck, ppzstrings, pblock)
59 struct sglobal *qglobal;
69 if (fcheck && *ppzstrings != NULL)
71 for (pz = *ppzstrings; *pz != NULL; pz++)
72 if (strcmp (zadd, *pz) == 0)
73 return UUCONF_SUCCESS;
81 clen = strlen (zadd) + 1;
82 znew = (char *) uuconf_malloc (pblock, clen);
86 qglobal->ierrno = errno;
87 return UUCONF_MALLOC_FAILED | UUCONF_ERROR_ERRNO;
89 memcpy ((pointer) znew, (pointer) zadd, clen);
94 if (pz == NULL || pz == (char **) &_uuconf_unset)
96 pz = (char **) uuconf_malloc (pblock, CSLOTS * sizeof (char *));
100 qglobal->ierrno = errno;
101 return UUCONF_MALLOC_FAILED | UUCONF_ERROR_ERRNO;
114 if ((c + 1) % CSLOTS == 0)
118 pznew = (char **) uuconf_malloc (pblock,
124 qglobal->ierrno = errno;
125 return UUCONF_MALLOC_FAILED | UUCONF_ERROR_ERRNO;
127 memcpy ((pointer) pznew, (pointer) *ppzstrings,
128 c * sizeof (char *));
129 uuconf_free (pblock, *ppzstrings);
138 return UUCONF_SUCCESS;