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