man-pages/man3/argz_add.3

206 lines
5.0 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
.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 );
2007-12-23 21:05:57 +00:00
.fi
2004-11-03 13:51:07 +00:00
.SH DESCRIPTION
2007-12-25 21:28:09 +00:00
These functions are glibc-specific.
2004-11-03 13:51:07 +00:00
.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
2008-06-09 15:49:35 +00:00
of strings, where the strings are separated by null bytes (\(aq\\0\(aq).
intro.1, time.1, adjtimex.2, capget.2, eventfd.2, fcntl.2, getrlimit.2, getsockopt.2, gettimeofday.2, intro.2, ioctl_list.2, ioperm.2, mlock.2, pivot_root.2, poll.2, prctl.2, ptrace.2, sched_setscheduler.2, select_tut.2, semget.2, sigaltstack.2, signalfd.2, sysctl.2, timer_settime.2, timerfd_create.2, wait.2, CPU_SET.3, argz_add.3, assert_perror.3, atexit.3, backtrace.3, bcmp.3, clearenv.3, ctime.3, dl_iterate_phdr.3, dlopen.3, ecvt.3, errno.3, error.3, ether_aton.3, exit.3, fenv.3, ferror.3, finite.3, flockfile.3, fnmatch.3, fpathconf.3, fpclassify.3, ftime.3, ftok.3, ftw.3, fwide.3, getaddrinfo.3, gethostbyname.3, getlogin.3, getnameinfo.3, getnetent.3, getopt.3, getprotoent.3, getrpcent.3, getservent.3, glob.3, hsearch.3, inet.3, isalpha.3, iswalnum.3, iswalpha.3, iswblank.3, iswcntrl.3, iswctype.3, iswdigit.3, iswgraph.3, iswlower.3, iswprint.3, iswpunct.3, iswspace.3, iswupper.3, iswxdigit.3, longjmp.3, lsearch.3, malloc.3, matherr.3, mblen.3, mbsinit.3, mbtowc.3, on_exit.3, printf.3, pthread_attr_init.3, pthread_attr_setaffinity_np.3, pthread_attr_setdetachstate.3, pthread_attr_setguardsize.3, pthread_attr_setinheritsched.3, pthread_attr_setschedparam.3, pthread_attr_setschedpolicy.3, pthread_attr_setscope.3, pthread_attr_setstack.3, pthread_attr_setstackaddr.3, pthread_attr_setstacksize.3, pthread_cancel.3, pthread_cleanup_push.3, pthread_equal.3, pthread_getattr_np.3, pthread_getcpuclockid.3, pthread_setaffinity_np.3, pthread_setcancelstate.3, pthread_setconcurrency.3, pthread_setschedparam.3, pthread_setschedprio.3, ptsname.3, putenv.3, putgrent.3, raise.3, rcmd.3, regex.3, rexec.3, rpc.3, rpmatch.3, rtnetlink.3, scandir.3, sem_init.3, setaliasent.3, setbuf.3, setenv.3, setjmp.3, signbit.3, stdio_ext.3, strtod.3, strtol.3, strtoul.3, system.3, termios.3, timeradd.3, tzset.3, ualarm.3, wctomb.3, xdr.3, st.4, tty_ioctl.4, core.5, elf.5, proc.5, bootparam.7, capabilities.7, icmp.7, ip.7, ipv6.7, math_error.7, mdoc.samples.7, mq_overview.7, pthreads.7, raw.7, regex.7, socket.7, tcp.7, tzselect.8: Global fix: s/non-zero/nonzero/ The tendency in English, as prescribed in style guides like Chicago MoS, is towards removing hyphens after prefixes like "non-" etc. Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2010-01-16 16:40:55 +00:00
If the length is nonzero, 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
2004-11-03 13:51:07 +00:00
.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 .
intro.1, time.1, accept.2, bind.2, connect.2, execve.2, flock.2, getdents.2, getpriority.2, getuid.2, intro.2, ioctl.2, mincore.2, mknod.2, personality.2, ptrace.2, read.2, recv.2, select_tut.2, send.2, sendfile.2, shmctl.2, sigaction.2, signal.2, stat.2, times.2, truncate.2, umask.2, wait.2, MB_CUR_MAX.3, MB_LEN_MAX.3, argz_add.3, btowc.3, clearenv.3, clock.3, cmsg.3, end.3, endian.3, errno.3, exit.3, fgetwc.3, fgetws.3, fopen.3, fputwc.3, fputws.3, fseek.3, fwide.3, getfsent.3, getgrnam.3, gethostid.3, getipnodebyname.3, getmntent.3, getpwnam.3, getwchar.3, grantpt.3, iconv.3, iconv_close.3, iconv_open.3, insque.3, intro.3, iswalnum.3, iswalpha.3, iswblank.3, iswcntrl.3, iswctype.3, iswdigit.3, iswgraph.3, iswlower.3, iswprint.3, iswpunct.3, iswspace.3, iswupper.3, iswxdigit.3, malloc.3, mblen.3, mbrlen.3, mbrtowc.3, mbsinit.3, mbsnrtowcs.3, mbsrtowcs.3, mbstowcs.3, mbtowc.3, mkstemp.3, mktemp.3, nl_langinfo.3, openpty.3, posix_openpt.3, printf.3, ptsname.3, putwchar.3, qecvt.3, rcmd.3, readdir.3, rexec.3, rpc.3, setnetgrent.3, shm_open.3, sigpause.3, stdin.3, stpcpy.3, strftime.3, strptime.3, syslog.3, towctrans.3, towlower.3, towupper.3, ttyslot.3, ungetwc.3, unlocked_stdio.3, wcpcpy.3, wcpncpy.3, wcrtomb.3, wcscasecmp.3, wcscat.3, wcschr.3, wcscmp.3, wcscpy.3, wcscspn.3, wcsdup.3, wcslen.3, wcsncasecmp.3, wcsncat.3, wcsncmp.3, wcsncpy.3, wcsnlen.3, wcsnrtombs.3, wcspbrk.3, wcsrchr.3, wcsrtombs.3, wcsspn.3, wcsstr.3, wcstok.3, wcstombs.3, wcswidth.3, wctob.3, wctomb.3, wctrans.3, wctype.3, wcwidth.3, wmemchr.3, wmemcmp.3, wmemcpy.3, wmemmove.3, wmemset.3, wprintf.3, console_ioctl.4, pts.4, elf.5, filesystems.5, hosts.5, proc.5, ttytype.5, boot.7, capabilities.7, credentials.7, epoll.7, glob.7, koi8-r.7, path_resolution.7, pty.7, signal.7, suffixes.7, time.7, unicode.7, unix.7, uri.7, utf-8.7: global fix: s/Unix/UNIX/ The man pages were rather inconsistent in the use of "Unix" versus "UNIX". Let's go with the trademark usage. Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2010-10-12 04:45:38 +00:00
For example, one might use this on a UNIX search path with
2008-06-09 15:49:35 +00:00
delimiter \(aq:\(aq.
2004-11-03 13:51:07 +00:00
.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,
2008-06-09 15:49:35 +00:00
the number of null bytes (\(aq\\0\(aq), in
2008-01-12 08:11:52 +00:00
.RI ( argz ,\ argz_len ).
2004-11-03 13:51:07 +00:00
.LP
.BR argz_create ()
intro.1, time.1, accept.2, bind.2, connect.2, execve.2, flock.2, getdents.2, getpriority.2, getuid.2, intro.2, ioctl.2, mincore.2, mknod.2, personality.2, ptrace.2, read.2, recv.2, select_tut.2, send.2, sendfile.2, shmctl.2, sigaction.2, signal.2, stat.2, times.2, truncate.2, umask.2, wait.2, MB_CUR_MAX.3, MB_LEN_MAX.3, argz_add.3, btowc.3, clearenv.3, clock.3, cmsg.3, end.3, endian.3, errno.3, exit.3, fgetwc.3, fgetws.3, fopen.3, fputwc.3, fputws.3, fseek.3, fwide.3, getfsent.3, getgrnam.3, gethostid.3, getipnodebyname.3, getmntent.3, getpwnam.3, getwchar.3, grantpt.3, iconv.3, iconv_close.3, iconv_open.3, insque.3, intro.3, iswalnum.3, iswalpha.3, iswblank.3, iswcntrl.3, iswctype.3, iswdigit.3, iswgraph.3, iswlower.3, iswprint.3, iswpunct.3, iswspace.3, iswupper.3, iswxdigit.3, malloc.3, mblen.3, mbrlen.3, mbrtowc.3, mbsinit.3, mbsnrtowcs.3, mbsrtowcs.3, mbstowcs.3, mbtowc.3, mkstemp.3, mktemp.3, nl_langinfo.3, openpty.3, posix_openpt.3, printf.3, ptsname.3, putwchar.3, qecvt.3, rcmd.3, readdir.3, rexec.3, rpc.3, setnetgrent.3, shm_open.3, sigpause.3, stdin.3, stpcpy.3, strftime.3, strptime.3, syslog.3, towctrans.3, towlower.3, towupper.3, ttyslot.3, ungetwc.3, unlocked_stdio.3, wcpcpy.3, wcpncpy.3, wcrtomb.3, wcscasecmp.3, wcscat.3, wcschr.3, wcscmp.3, wcscpy.3, wcscspn.3, wcsdup.3, wcslen.3, wcsncasecmp.3, wcsncat.3, wcsncmp.3, wcsncpy.3, wcsnlen.3, wcsnrtombs.3, wcspbrk.3, wcsrchr.3, wcsrtombs.3, wcsspn.3, wcsstr.3, wcstok.3, wcstombs.3, wcswidth.3, wctob.3, wctomb.3, wctrans.3, wctype.3, wcwidth.3, wmemchr.3, wmemcmp.3, wmemcpy.3, wmemmove.3, wmemset.3, wprintf.3, console_ioctl.4, pts.4, elf.5, filesystems.5, hosts.5, proc.5, ttytype.5, boot.7, capabilities.7, credentials.7, epoll.7, glob.7, koi8-r.7, path_resolution.7, pty.7, signal.7, suffixes.7, time.7, unicode.7, unix.7, uri.7, utf-8.7: global fix: s/Unix/UNIX/ The man pages were rather inconsistent in the use of "Unix" versus "UNIX". Let's go with the trademark usage. Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2010-10-12 04:45:38 +00:00
converts a UNIX-style argument vector
2004-11-03 13:51:07 +00:00
.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
2008-01-12 08:11:52 +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
2008-01-12 08:11:52 +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
2008-01-12 08:11:52 +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,
intro.1, time.1, accept.2, bind.2, connect.2, execve.2, flock.2, getdents.2, getpriority.2, getuid.2, intro.2, ioctl.2, mincore.2, mknod.2, personality.2, ptrace.2, read.2, recv.2, select_tut.2, send.2, sendfile.2, shmctl.2, sigaction.2, signal.2, stat.2, times.2, truncate.2, umask.2, wait.2, MB_CUR_MAX.3, MB_LEN_MAX.3, argz_add.3, btowc.3, clearenv.3, clock.3, cmsg.3, end.3, endian.3, errno.3, exit.3, fgetwc.3, fgetws.3, fopen.3, fputwc.3, fputws.3, fseek.3, fwide.3, getfsent.3, getgrnam.3, gethostid.3, getipnodebyname.3, getmntent.3, getpwnam.3, getwchar.3, grantpt.3, iconv.3, iconv_close.3, iconv_open.3, insque.3, intro.3, iswalnum.3, iswalpha.3, iswblank.3, iswcntrl.3, iswctype.3, iswdigit.3, iswgraph.3, iswlower.3, iswprint.3, iswpunct.3, iswspace.3, iswupper.3, iswxdigit.3, malloc.3, mblen.3, mbrlen.3, mbrtowc.3, mbsinit.3, mbsnrtowcs.3, mbsrtowcs.3, mbstowcs.3, mbtowc.3, mkstemp.3, mktemp.3, nl_langinfo.3, openpty.3, posix_openpt.3, printf.3, ptsname.3, putwchar.3, qecvt.3, rcmd.3, readdir.3, rexec.3, rpc.3, setnetgrent.3, shm_open.3, sigpause.3, stdin.3, stpcpy.3, strftime.3, strptime.3, syslog.3, towctrans.3, towlower.3, towupper.3, ttyslot.3, ungetwc.3, unlocked_stdio.3, wcpcpy.3, wcpncpy.3, wcrtomb.3, wcscasecmp.3, wcscat.3, wcschr.3, wcscmp.3, wcscpy.3, wcscspn.3, wcsdup.3, wcslen.3, wcsncasecmp.3, wcsncat.3, wcsncmp.3, wcsncpy.3, wcsnlen.3, wcsnrtombs.3, wcspbrk.3, wcsrchr.3, wcsrtombs.3, wcsspn.3, wcsstr.3, wcstok.3, wcstombs.3, wcswidth.3, wctob.3, wctomb.3, wctrans.3, wctype.3, wcwidth.3, wmemchr.3, wmemcmp.3, wmemcpy.3, wmemmove.3, wmemset.3, wprintf.3, console_ioctl.4, pts.4, elf.5, filesystems.5, hosts.5, proc.5, ttytype.5, boot.7, capabilities.7, credentials.7, epoll.7, glob.7, koi8-r.7, path_resolution.7, pty.7, signal.7, suffixes.7, time.7, unicode.7, unix.7, uri.7, utf-8.7: global fix: s/Unix/UNIX/ The man pages were rather inconsistent in the use of "Unix" versus "UNIX". Let's go with the trademark usage. Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2010-10-12 04:45:38 +00:00
making a UNIX-style argv vector.
2004-11-03 13:51:07 +00:00
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
2008-06-09 15:49:35 +00:00
all null bytes (\(aq\\0\(aq) 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)