]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - lib/libc/gen/stringlist.3
libsys: fix sleep(3)/usleep(3) cancel behavior
[FreeBSD/FreeBSD.git] / lib / libc / gen / stringlist.3
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
52 The
53 .Nm
54 functions manipulate stringlists, which are lists of
55 strings that extend automatically if necessary.
56 .Pp
57 The
58 .Vt StringList
59 structure has the following definition:
60 .Bd -literal -offset indent
61 typedef 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
69 a pointer to the base of the array containing the list.
70 .It Va sl_max
71 the size of
72 .Va sl_str .
73 .It Va sl_cur
74 the offset in
75 .Va sl_str
76 of the current element.
77 .El
78 .Pp
79 The following stringlist manipulation functions are available:
80 .Bl -tag -width "sl_init()"
81 .It Fn sl_init
82 Create a stringlist.
83 Returns a pointer to a
84 .Vt StringList ,
85 or
86 .Dv NULL
87 in case of failure.
88 .It Fn sl_free
89 Releases memory occupied by
90 .Fa sl
91 and the
92 .Fa sl->sl_str
93 array.
94 If
95 .Fa freeall
96 is non-zero, then each of the items within
97 .Fa sl->sl_str
98 is released as well.
99 .It Fn sl_add
100 Add
101 .Fa item
102 to
103 .Fa sl->sl_str
104 at
105 .Fa sl->sl_cur ,
106 extending the size of
107 .Fa sl->sl_str .
108 Returns zero upon success, \-1 upon failure.
109 .It Fn sl_find
110 Find
111 .Fa item
112 in
113 .Fa sl ,
114 returning NULL if it is not found.
115 .El
116 .Sh SEE ALSO
117 .Xr free 3 ,
118 .Xr malloc 3
119 .Sh HISTORY
120 The
121 .Nm
122 functions appeared in
123 .Fx 2.2.6
124 and
125 .Nx 1.3 .