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