OSDN Git Service

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