man-pages/man3/argz_add.3

206 lines
4.9 KiB
Groff
Raw Normal View History

2004-11-03 13:51:07 +00:00
.\" Copyright 2002 walter harms (walter.harms@informatik.uni-oldenburg.de)
.\" Distributed under GPL
.\" based on the description in glibc source and infopages
.\"
2004-11-03 13:51:07 +00:00
.\" Corrections and additions, aeb
.TH ARGZ_ADD 3 2007-05-18 "" "Linux Programmer's Manual"
2004-11-03 13:51:07 +00:00
.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
.sp
.B "#include <argz.h>"
.sp
2007-12-22 21:52:46 +00:00
.BI "error_t argz_add(char **" argz ", size_t *" argz_len \
", const char *" str );
2004-11-03 13:51:07 +00:00
.sp
2007-12-22 21:52:46 +00:00
.BI "error_t argz_add_sep(char **" argz ", size_t *" argz_len ,
2004-11-03 13:51:07 +00:00
.ti 20n
.BI "const char *" str ", int " delim );
.sp
2007-12-22 21:52:46 +00:00
.BI "error_t argz_append(char **" argz ", size_t *" argz_len ,
2004-11-03 13:51:07 +00:00
.ti 20n
.BI "const char *" buf ", size_t " buf_len );
.sp
2007-12-22 21:52:46 +00:00
.BI "size_t argz_count(const char *" argz ", size_t " argz_len );
2004-11-03 13:51:07 +00:00
.sp
2007-12-22 21:52:46 +00:00
.BI "error_t argz_create(char * const " argv "[], char **" argz ,
2004-11-03 13:51:07 +00:00
.ti 20n
.BI "size_t *" argz_len );
.sp
2007-12-22 21:52:46 +00:00
.BI "error_t argz_create_sep(const char *" str ", int " sep ", char **" argz ,
2004-11-03 13:51:07 +00:00
.ti 20n
.BI "size_t *" argz_len );
.sp
2007-12-22 21:52:46 +00:00
.BI "error_t argz_delete(char **" argz ", size_t *" argz_len ", char *" entry );
2004-11-03 13:51:07 +00:00
.sp
2007-12-22 21:52:46 +00:00
.BI "void argz_extract(char *" argz ", size_t " argz_len ", char **" argv );
2004-11-03 13:51:07 +00:00
.sp
2007-12-22 21:52:46 +00:00
.BI "error_t argz_insert(char **" argz ", size_t *" argz_len ", char *" before ,
2004-11-03 13:51:07 +00:00
.ti 20n
.BI "const char *" entry );
.sp
2007-12-22 21:52:46 +00:00
.BI "char *argz_next(char *" argz ", size_t " argz_len ", const char *" entry );
2004-11-03 13:51:07 +00:00
.sp
2007-12-22 21:52:46 +00:00
.BI "error_t argz_replace(char **" argz ", size_t *" argz_len \
", const char *" str ,
2004-11-03 13:51:07 +00:00
.ti 20n
.BI "const char *" with ", unsigned int *" replace_count );
.sp
2007-12-22 21:52:46 +00:00
.BI "void argz_stringify(char *" argz ", size_t " len ", int " sep );
2004-11-03 13:51:07 +00:00
.SH DESCRIPTION
These functions are glibc-specific.
.LP
An argz vector is a pointer to a character buffer together with a length.
2006-05-15 20:52:20 +00:00
The intended interpretation of the character buffer is an array
of strings, where the strings are separated by null bytes ('\\0').
If the length is non-zero, the last byte of the buffer must be a null byte.
2004-11-03 13:51:07 +00:00
.LP
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.
.LP
.BR argz_add ()
2004-11-03 13:51:07 +00:00
adds the string
.I str
at the end of the array
2007-12-22 21:52:46 +00:00
.IR *argz ,
2004-11-03 13:51:07 +00:00
and updates
2007-12-22 21:52:46 +00:00
.I *argz
2004-11-03 13:51:07 +00:00
and
2007-12-22 21:52:46 +00:00
.IR *argz_len .
2004-11-03 13:51:07 +00:00
.LP
.BR argz_add_sep ()
2004-11-03 13:51:07 +00:00
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 ':'.
.LP
.BR argz_append ()
2004-11-03 13:51:07 +00:00
appends the argz vector
2007-12-22 22:01:09 +00:00
.RI ( buf ,\ buf_len )
2004-11-03 13:51:07 +00:00
after
2007-12-22 21:52:46 +00:00
.RI ( *argz ,\ *argz_len )
2004-11-03 13:51:07 +00:00
and updates
2007-12-22 21:52:46 +00:00
.IR *argz
2004-11-03 13:51:07 +00:00
and
2007-12-22 21:52:46 +00:00
.IR *argz_len .
2004-11-03 13:51:07 +00:00
(Thus,
2007-12-22 21:52:46 +00:00
.I *argz_len
2004-11-03 13:51:07 +00:00
will be increased by
.IR buf_len .)
.LP
.BR argz_count ()
counts the number of strings, that is,
the number of null bytes ('\\0'), in
2007-12-22 22:01:09 +00:00
.RI ( argz ,\ argz_len ).
2004-11-03 13:51:07 +00:00
.LP
.BR argz_create ()
2004-11-03 13:51:07 +00:00
converts a Unix-style argument vector
.IR argv ,
2007-12-22 21:52:46 +00:00
terminated by
.IR "(char *) 0" ,
into an argz vector
.RI ( *argz ,\ *argz_len ).
2004-11-03 13:51:07 +00:00
.LP
.BR argz_create_sep ()
converts the null-terminated string
2004-11-03 13:51:07 +00:00
.I str
into an argz vector
2007-12-22 21:52:46 +00:00
.RI ( *argz ,\ *argz_len )
2004-11-03 13:51:07 +00:00
by breaking it up at every occurrence of the separator
.IR sep .
.LP
.BR argz_delete ()
2004-11-03 13:51:07 +00:00
removes the substring pointed to by
.I entry
from the argz vector
2007-12-22 21:52:46 +00:00
.RI ( *argz ,\ *argz_len )
2004-11-03 13:51:07 +00:00
and updates
2007-12-22 21:52:46 +00:00
.I *argz
2004-11-03 13:51:07 +00:00
and
2007-12-22 21:52:46 +00:00
.IR *argz_len .
2004-11-03 13:51:07 +00:00
.LP
.BR argz_extract ()
2004-11-03 13:51:07 +00:00
is the opposite of
.BR argz_create ().
2004-11-03 13:51:07 +00:00
It takes the argz vector
2007-12-22 22:01:09 +00:00
.RI ( argz ,\ argz_len )
2004-11-03 13:51:07 +00:00
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.
.LP
.BR argz_insert ()
2004-11-03 13:51:07 +00:00
is the opposite of
.BR argz_delete ().
2004-11-03 13:51:07 +00:00
It inserts the argument
.I entry
at position
.I before
into the argz vector
2007-12-22 22:01:09 +00:00
.RI ( *argz ,\ *argz_len )
2004-11-03 13:51:07 +00:00
and updates
2007-12-22 21:52:46 +00:00
.I *argz
2004-11-03 13:51:07 +00:00
and
2007-12-22 21:52:46 +00:00
.IR *argz_len .
2004-11-03 13:51:07 +00:00
If
.I before
is NULL, then
.I entry
will inserted at the end.
.LP
.BR argz_next ()
is a function to step trough the argz vector.
If
2004-11-03 13:51:07 +00:00
.I entry
is NULL, the first entry is returned.
Otherwise, the entry
following is returned.
It returns NULL if there is no following entry.
2004-11-03 13:51:07 +00:00
.LP
.BR argz_replace ()
2004-11-03 13:51:07 +00:00
replaces each occurrence of
.I str
with
.IR with ,
reallocating argz as necessary.
If
2004-11-03 13:51:07 +00:00
.I replace_count
is non-NULL,
2007-12-22 21:52:46 +00:00
.I *replace_count
2004-11-03 13:51:07 +00:00
will be incremented by the number of replacements.
.LP
.BR argz_stringify ()
2004-11-03 13:51:07 +00:00
is the opposite of
.BR argz_create_sep ().
2004-11-03 13:51:07 +00:00
It transforms the argz vector into a normal string by replacing
all null bytes ('\\0') except the last by
2004-11-03 13:51:07 +00:00
.IR sep .
.SH "RETURN VALUE"
All argz functions that do memory allocation have a return type of
2005-10-19 13:17:47 +00:00
\fIerror_t\fP, and return 0 for success, and \fBENOMEM\fP
2004-11-03 13:51:07 +00:00
if an allocation error occurs.
2006-08-08 16:26:04 +00:00
.SH CONFORMING TO
These functions are a GNU extension.
Handle with care.
.SH BUGS
Argz vectors without a terminating null byte may lead to
Segmentation Faults.
2004-11-03 13:51:07 +00:00
.SH "SEE ALSO"
2007-12-05 20:52:37 +00:00
.BR envz_add (3)