Debian Codegraph @

upstream/debian-trixie/man3/argz_add.3

raw
1 '\" t
2 .\" Copyright 2002 walter harms ([email protected])
3 .\"
4 .\" SPDX-License-Identifier: GPL-1.0-or-later
5 .\"
6 .\" based on the description in glibc source and infopages
7 .\"
8 .\" Corrections and additions, aeb
9 .TH argz_add 3 2024-06-15 "Linux man-pages 6.9.1"
10 .SH NAME
11 argz_add, argz_add_sep, argz_append, argz_count, argz_create,
12 argz_create_sep, argz_delete, argz_extract, argz_insert,
13 argz_next, argz_replace, argz_stringify \- functions to handle an argz list
14 .SH LIBRARY
15 Standard C library
16 .RI ( libc ", " \-lc )
17 .SH SYNOPSIS
18 .nf
19 .B "#include <argz.h>"
20 .P
21 .BI "error_t argz_add(char **restrict " argz ", size_t *restrict " argz_len ,
22 .BI " const char *restrict " str );
23 .P
24 .BI "error_t argz_add_sep(char **restrict " argz \
25 ", size_t *restrict " argz_len ,
26 .BI " const char *restrict " str ", int " delim );
27 .P
28 .BI "error_t argz_append(char **restrict " argz ", size_t *restrict " argz_len ,
29 .BI " const char *restrict " buf ", size_t " buf_len );
30 .P
31 .BI "size_t argz_count(const char *" argz ", size_t " argz_len );
32 .P
33 .BI "error_t argz_create(char *const " argv "[], char **restrict " argz ,
34 .BI " size_t *restrict " argz_len );
35 .P
36 .BI "error_t argz_create_sep(const char *restrict " str ", int " sep ,
37 .BI " char **restrict " argz ", size_t *restrict " argz_len );
38 .P
39 .BI "void argz_delete(char **restrict " argz ", size_t *restrict " argz_len ,
40 .BI " char *restrict " entry );
41 .P
42 .BI "void argz_extract(const char *restrict " argz ", size_t " argz_len ,
43 .BI " char **restrict " argv );
44 .P
45 .BI "error_t argz_insert(char **restrict " argz ", size_t *restrict " argz_len ,
46 .BI " char *restrict " before ", const char *restrict " entry );
47 .P
48 .BI "char *argz_next(const char *restrict " argz ", size_t " argz_len ,
49 .BI " const char *restrict " entry );
50 .P
51 .BI "error_t argz_replace(char **restrict " argz \
52 ", size_t *restrict " argz_len ,
53 .BI " const char *restrict " str ", const char *restrict " with ,
54 .BI " unsigned int *restrict " replace_count );
55 .P
56 .BI "void argz_stringify(char *" argz ", size_t " len ", int " sep );
57 .fi
58 .SH DESCRIPTION
59 These functions are glibc-specific.
60 .P
61 An argz vector is a pointer to a character buffer together with a length.
62 The intended interpretation of the character buffer is an array
63 of strings, where the strings are separated by null bytes (\[aq]\[rs]0\[aq]).
64 If the length is nonzero, the last byte of the buffer must be a null byte.
65 .P
66 These functions are for handling argz vectors.
67 The pair (NULL,0) is an argz vector, and, conversely,
68 argz vectors of length 0 must have null pointer.
69 Allocation of nonempty argz vectors is done using
70 .BR malloc (3),
71 so that
72 .BR free (3)
73 can be used to dispose of them again.
74 .P
75 .BR argz_add ()
76 adds the string
77 .I str
78 at the end of the array
79 .IR *argz ,
80 and updates
81 .I *argz
82 and
83 .IR *argz_len .
84 .P
85 .BR argz_add_sep ()
86 is similar, but splits the string
87 .I str
88 into substrings separated by the delimiter
89 .IR delim .
90 For example, one might use this on a UNIX search path with
91 delimiter \[aq]:\[aq].
92 .P
93 .BR argz_append ()
94 appends the argz vector
95 .RI ( buf ,\ buf_len )
96 after
97 .RI ( *argz ,\ *argz_len )
98 and updates
99 .I *argz
100 and
101 .IR *argz_len .
102 (Thus,
103 .I *argz_len
104 will be increased by
105 .IR buf_len .)
106 .P
107 .BR argz_count ()
108 counts the number of strings, that is,
109 the number of null bytes (\[aq]\[rs]0\[aq]), in
110 .RI ( argz ,\ argz_len ).
111 .P
112 .BR argz_create ()
113 converts a UNIX-style argument vector
114 .IR argv ,
115 terminated by
116 .IR "(char\ *)\ 0" ,
117 into an argz vector
118 .RI ( *argz ,\ *argz_len ).
119 .P
120 .BR argz_create_sep ()
121 converts the null-terminated string
122 .I str
123 into an argz vector
124 .RI ( *argz ,\ *argz_len )
125 by breaking it up at every occurrence of the separator
126 .IR sep .
127 .P
128 .BR argz_delete ()
129 removes the substring pointed to by
130 .I entry
131 from the argz vector
132 .RI ( *argz ,\ *argz_len )
133 and updates
134 .I *argz
135 and
136 .IR *argz_len .
137 .P
138 .BR argz_extract ()
139 is the opposite of
140 .BR argz_create ().
141 It takes the argz vector
142 .RI ( argz ,\ argz_len )
143 and fills the array starting at
144 .I argv
145 with pointers to the substrings, and a final NULL,
146 making a UNIX-style argv vector.
147 The array
148 .I argv
149 must have room for
150 .IR argz_count ( argz ", " argz_len ") + 1"
151 pointers.
152 .P
153 .BR argz_insert ()
154 is the opposite of
155 .BR argz_delete ().
156 It inserts the argument
157 .I entry
158 at position
159 .I before
160 into the argz vector
161 .RI ( *argz ,\ *argz_len )
162 and updates
163 .I *argz
164 and
165 .IR *argz_len .
166 If
167 .I before
168 is NULL, then
169 .I entry
170 will inserted at the end.
171 .P
172 .BR argz_next ()
173 is a function to step through the argz vector.
174 If
175 .I entry
176 is NULL, the first entry is returned.
177 Otherwise, the entry
178 following is returned.
179 It returns NULL if there is no following entry.
180 .P
181 .BR argz_replace ()
182 replaces each occurrence of
183 .I str
184 with
185 .IR with ,
186 reallocating argz as necessary.
187 If
188 .I replace_count
189 is non-NULL,
190 .I *replace_count
191 will be incremented by the number of replacements.
192 .P
193 .BR argz_stringify ()
194 is the opposite of
195 .BR argz_create_sep ().
196 It transforms the argz vector into a normal string by replacing
197 all null bytes (\[aq]\[rs]0\[aq]) except the last by
198 .IR sep .
199 .SH RETURN VALUE
200 All argz functions that do memory allocation have a return type of
201 .I error_t
202 (an integer type),
203 and return 0 for success, and
204 .B ENOMEM
205 if an allocation error occurs.
206 .SH ATTRIBUTES
207 For an explanation of the terms used in this section, see
208 .BR attributes (7).
209 .TS
210 allbox;
211 lbx lb lb
212 l l l.
213 Interface Attribute Value
214 T{
215 .na
216 .nh
217 .BR argz_add (),
218 .BR argz_add_sep (),
219 .BR argz_append (),
220 .BR argz_count (),
221 .BR argz_create (),
222 .BR argz_create_sep (),
223 .BR argz_delete (),
224 .BR argz_extract (),
225 .BR argz_insert (),
226 .BR argz_next (),
227 .BR argz_replace (),
228 .BR argz_stringify ()
229 T} Thread safety MT-Safe
230 .TE
231 .SH STANDARDS
232 GNU.
233 .SH BUGS
234 Argz vectors without a terminating null byte may lead to
235 Segmentation Faults.
236 .SH SEE ALSO
237 .BR envz_add (3)