xref: /freebsd/lib/libc/gen/stringlist.3 (revision db33c6f3ae9d1231087710068ee4ea5398aacca7)
1.\"	$NetBSD: stringlist.3,v 1.5 1999/03/22 19:44:46 garbled Exp $
2.\"
3.\" Copyright (c) 1997, 1999 The NetBSD Foundation, Inc.
4.\" All rights reserved.
5.\"
6.\" This file was contributed to The NetBSD Foundation by Luke Mewburn.
7.\"
8.\" Redistribution and use in source and binary forms, with or without
9.\" modification, are permitted provided that the following conditions
10.\" are met:
11.\" 1. Redistributions of source code must retain the above copyright
12.\"    notice, this list of conditions and the following disclaimer.
13.\" 2. Redistributions in binary form must reproduce the above copyright
14.\"    notice, this list of conditions and the following disclaimer in the
15.\"    documentation and/or other materials provided with the distribution.
16.\"
17.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
18.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE
21.\" LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27.\" POSSIBILITY OF SUCH DAMAGE.
28.\"
29.Dd November 28, 1999
30.Dt STRINGLIST 3
31.Os
32.Sh NAME
33.Nm stringlist ,
34.Nm sl_init ,
35.Nm sl_add ,
36.Nm sl_free ,
37.Nm sl_find
38.Nd stringlist manipulation functions
39.Sh LIBRARY
40.Lb libc
41.Sh SYNOPSIS
42.In stringlist.h
43.Ft StringList *
44.Fn sl_init
45.Ft int
46.Fn sl_add "StringList *sl" "char *item"
47.Ft void
48.Fn sl_free "StringList *sl" "int freeall"
49.Ft char *
50.Fn sl_find "StringList *sl" "const char *item"
51.Sh DESCRIPTION
52The
53.Nm
54functions manipulate stringlists, which are lists of
55strings that extend automatically if necessary.
56.Pp
57The
58.Vt StringList
59structure has the following definition:
60.Bd -literal -offset indent
61typedef struct _stringlist {
62	char	**sl_str;
63	size_t	  sl_max;
64	size_t	  sl_cur;
65} StringList;
66.Ed
67.Bl -tag -width "sl_str" -offset indent
68.It Va sl_str
69a pointer to the base of the array containing the list.
70.It Va sl_max
71the size of
72.Va sl_str .
73.It Va sl_cur
74the offset in
75.Va sl_str
76of the current element.
77.El
78.Pp
79The following stringlist manipulation functions are available:
80.Bl -tag -width "sl_init()"
81.It Fn sl_init
82Create a stringlist.
83Returns a pointer to a
84.Vt StringList ,
85or
86.Dv NULL
87in case of failure.
88.It Fn sl_free
89Releases memory occupied by
90.Fa sl
91and the
92.Fa sl->sl_str
93array.
94If
95.Fa freeall
96is non-zero, then each of the items within
97.Fa sl->sl_str
98is released as well.
99.It Fn sl_add
100Add
101.Fa item
102to
103.Fa sl->sl_str
104at
105.Fa sl->sl_cur ,
106extending the size of
107.Fa sl->sl_str .
108Returns zero upon success, \-1 upon failure.
109.It Fn sl_find
110Find
111.Fa item
112in
113.Fa sl ,
114returning NULL if it is not found.
115.El
116.Sh SEE ALSO
117.Xr free 3 ,
118.Xr malloc 3
119.Sh HISTORY
120The
121.Nm
122functions appeared in
123.Fx 2.2.6
124and
125.Nx 1.3 .
126