Back to index

glibc  2.9
argz.h
Go to the documentation of this file.
00001 /* Routines for dealing with '\0' separated arg vectors.
00002    Copyright (C) 1995,96,97,98,99,2000,2004,2007 Free Software Foundation, Inc.
00003    This file is part of the GNU C Library.
00004 
00005    The GNU C Library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Lesser General Public
00007    License as published by the Free Software Foundation; either
00008    version 2.1 of the License, or (at your option) any later version.
00009 
00010    The GNU C Library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Lesser General Public License for more details.
00014 
00015    You should have received a copy of the GNU Lesser General Public
00016    License along with the GNU C Library; if not, write to the Free
00017    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00018    02111-1307 USA.  */
00019 
00020 #ifndef _ARGZ_H
00021 #define _ARGZ_H      1
00022 
00023 #include <features.h>
00024 
00025 #define __need_error_t
00026 #include <errno.h>
00027 #include <string.h>         /* Need size_t, and strchr is called below.  */
00028 
00029 #ifndef __const
00030 # define __const const
00031 #endif
00032 
00033 #ifndef __error_t_defined
00034 typedef int error_t;
00035 #endif
00036 
00037 
00038 __BEGIN_DECLS
00039 
00040 /* Make a '\0' separated arg vector from a unix argv vector, returning it in
00041    ARGZ, and the total length in LEN.  If a memory allocation error occurs,
00042    ENOMEM is returned, otherwise 0.  The result can be destroyed using free. */
00043 extern error_t __argz_create (char *__const __argv[], char **__restrict __argz,
00044                            size_t *__restrict __len) __THROW;
00045 extern error_t argz_create (char *__const __argv[], char **__restrict __argz,
00046                          size_t *__restrict __len) __THROW;
00047 
00048 /* Make a '\0' separated arg vector from a SEP separated list in
00049    STRING, returning it in ARGZ, and the total length in LEN.  If a
00050    memory allocation error occurs, ENOMEM is returned, otherwise 0.
00051    The result can be destroyed using free.  */
00052 extern error_t __argz_create_sep (__const char *__restrict __string,
00053                               int __sep, char **__restrict __argz,
00054                               size_t *__restrict __len) __THROW;
00055 extern error_t argz_create_sep (__const char *__restrict __string,
00056                             int __sep, char **__restrict __argz,
00057                             size_t *__restrict __len) __THROW;
00058 
00059 /* Returns the number of strings in ARGZ.  */
00060 extern size_t __argz_count (__const char *__argz, size_t __len)
00061      __THROW __attribute_pure__;
00062 extern size_t argz_count (__const char *__argz, size_t __len)
00063      __THROW __attribute_pure__;
00064 
00065 /* Puts pointers to each string in ARGZ into ARGV, which must be large enough
00066    to hold them all.  */
00067 extern void __argz_extract (__const char *__restrict __argz, size_t __len,
00068                          char **__restrict __argv) __THROW;
00069 extern void argz_extract (__const char *__restrict __argz, size_t __len,
00070                        char **__restrict __argv) __THROW;
00071 
00072 /* Make '\0' separated arg vector ARGZ printable by converting all the '\0's
00073    except the last into the character SEP.  */
00074 extern void __argz_stringify (char *__argz, size_t __len, int __sep) __THROW;
00075 extern void argz_stringify (char *__argz, size_t __len, int __sep) __THROW;
00076 
00077 /* Append BUF, of length BUF_LEN to the argz vector in ARGZ & ARGZ_LEN.  */
00078 extern error_t __argz_append (char **__restrict __argz,
00079                            size_t *__restrict __argz_len,
00080                            __const char *__restrict __buf, size_t _buf_len)
00081      __THROW;
00082 extern error_t argz_append (char **__restrict __argz,
00083                          size_t *__restrict __argz_len,
00084                          __const char *__restrict __buf, size_t __buf_len)
00085      __THROW;
00086 
00087 /* Append STR to the argz vector in ARGZ & ARGZ_LEN.  */
00088 extern error_t __argz_add (char **__restrict __argz,
00089                         size_t *__restrict __argz_len,
00090                         __const char *__restrict __str) __THROW;
00091 extern error_t argz_add (char **__restrict __argz,
00092                       size_t *__restrict __argz_len,
00093                       __const char *__restrict __str) __THROW;
00094 
00095 /* Append SEP separated list in STRING to the argz vector in ARGZ &
00096    ARGZ_LEN.  */
00097 extern error_t __argz_add_sep (char **__restrict __argz,
00098                             size_t *__restrict __argz_len,
00099                             __const char *__restrict __string, int __delim)
00100      __THROW;
00101 extern error_t argz_add_sep (char **__restrict __argz,
00102                           size_t *__restrict __argz_len,
00103                           __const char *__restrict __string, int __delim)
00104      __THROW;
00105 
00106 /* Delete ENTRY from ARGZ & ARGZ_LEN, if it appears there.  */
00107 extern void __argz_delete (char **__restrict __argz,
00108                         size_t *__restrict __argz_len,
00109                         char *__restrict __entry) __THROW;
00110 extern void argz_delete (char **__restrict __argz,
00111                       size_t *__restrict __argz_len,
00112                       char *__restrict __entry) __THROW;
00113 
00114 /* Insert ENTRY into ARGZ & ARGZ_LEN before BEFORE, which should be an
00115    existing entry in ARGZ; if BEFORE is NULL, ENTRY is appended to the end.
00116    Since ARGZ's first entry is the same as ARGZ, argz_insert (ARGZ, ARGZ_LEN,
00117    ARGZ, ENTRY) will insert ENTRY at the beginning of ARGZ.  If BEFORE is not
00118    in ARGZ, EINVAL is returned, else if memory can't be allocated for the new
00119    ARGZ, ENOMEM is returned, else 0.  */
00120 extern error_t __argz_insert (char **__restrict __argz,
00121                            size_t *__restrict __argz_len,
00122                            char *__restrict __before,
00123                            __const char *__restrict __entry) __THROW;
00124 extern error_t argz_insert (char **__restrict __argz,
00125                          size_t *__restrict __argz_len,
00126                          char *__restrict __before,
00127                          __const char *__restrict __entry) __THROW;
00128 
00129 /* Replace any occurrences of the string STR in ARGZ with WITH, reallocating
00130    ARGZ as necessary.  If REPLACE_COUNT is non-zero, *REPLACE_COUNT will be
00131    incremented by number of replacements performed.  */
00132 extern error_t __argz_replace (char **__restrict __argz,
00133                             size_t *__restrict __argz_len,
00134                             __const char *__restrict __str,
00135                             __const char *__restrict __with,
00136                             unsigned int *__restrict __replace_count);
00137 extern error_t argz_replace (char **__restrict __argz,
00138                           size_t *__restrict __argz_len,
00139                           __const char *__restrict __str,
00140                           __const char *__restrict __with,
00141                           unsigned int *__restrict __replace_count);
00142 
00143 /* Returns the next entry in ARGZ & ARGZ_LEN after ENTRY, or NULL if there
00144    are no more.  If entry is NULL, then the first entry is returned.  This
00145    behavior allows two convenient iteration styles:
00146 
00147     char *entry = 0;
00148     while ((entry = argz_next (argz, argz_len, entry)))
00149       ...;
00150 
00151    or
00152 
00153     char *entry;
00154     for (entry = argz; entry; entry = argz_next (argz, argz_len, entry))
00155       ...;
00156 */
00157 extern char *__argz_next (__const char *__restrict __argz, size_t __argz_len,
00158                        __const char *__restrict __entry) __THROW;
00159 extern char *argz_next (__const char *__restrict __argz, size_t __argz_len,
00160                      __const char *__restrict __entry) __THROW;
00161 
00162 #ifdef __USE_EXTERN_INLINES
00163 __extern_inline char *
00164 __NTH (__argz_next (__const char *__argz, size_t __argz_len,
00165                   __const char *__entry))
00166 {
00167   if (__entry)
00168     {
00169       if (__entry < __argz + __argz_len)
00170        __entry = strchr (__entry, '\0') + 1;
00171 
00172       return __entry >= __argz + __argz_len ? (char *) NULL : (char *) __entry;
00173     }
00174   else
00175     return __argz_len > 0 ? (char *) __argz : 0;
00176 }
00177 __extern_inline char *
00178 __NTH (argz_next (__const char *__argz, size_t __argz_len,
00179                 __const char *__entry))
00180 {
00181   return __argz_next (__argz, __argz_len, __entry);
00182 }
00183 #endif /* Use extern inlines.  */
00184 
00185 __END_DECLS
00186 
00187 #endif /* argz.h */