1 /* Routines for dealing with '\0' separated arg vectors.
2 Copyright (C) 1995,96,97,98,99,2000,2004,2007 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
22 #define __need_error_t
24 #include <string.h> /* Need size_t, and strchr is called below. */
30 #ifndef __error_t_defined
36 /* Make a '\0' separated arg vector from a unix argv vector, returning it in
37 ARGZ, and the total length in LEN. If a memory allocation error occurs,
38 ENOMEM is returned, otherwise 0. The result can be destroyed using free. */
40 extern error_t argz_create (char *const __argv[], char **restrict __argz,
41 size_t *restrict __len);
43 /* Make a '\0' separated arg vector from a SEP separated list in
44 STRING, returning it in ARGZ, and the total length in LEN. If a
45 memory allocation error occurs, ENOMEM is returned, otherwise 0.
46 The result can be destroyed using free. */
48 extern error_t argz_create_sep (const char *restrict string,
49 int __sep, char **restrict __argz,
50 size_t *restrict __len);
52 /* Returns the number of strings in ARGZ. */
54 extern size_t argz_count (const char *__argz, size_t __len)
57 /* Puts pointers to each string in ARGZ into ARGV, which must be large enough
60 extern void argz_extract (const char *restrict __argz, size_t __len,
61 char **restrict __argv);
63 /* Make '\0' separated arg vector ARGZ printable by converting all the '\0's
64 except the last into the character SEP. */
66 extern void argz_stringify (char *__argz, size_t __len, int __sep);
68 /* Append BUF, of length BUF_LEN to the argz vector in ARGZ & ARGZ_LEN. */
70 extern error_t argz_append (char **restrict __argz,
71 size_t *restrict __argz_len,
72 const char *restrict __buf, size_t __buf_len)
75 /* Append STR to the argz vector in ARGZ & ARGZ_LEN. */
77 extern error_t argz_add (char **restrict __argz,
78 size_t *restrict __argz_len,
79 const char *restrict str);
81 /* Append SEP separated list in STRING to the argz vector in ARGZ &
84 extern error_t argz_add_sep (char **restrict __argz,
85 size_t *restrict __argz_len,
86 const char *restrict string, int __delim)
89 /* Delete ENTRY from ARGZ & ARGZ_LEN, if it appears there. */
91 extern void argz_delete (char **restrict __argz,
92 size_t *restrict __argz_len,
93 char *restrict __entry);
95 /* Insert ENTRY into ARGZ & ARGZ_LEN before BEFORE, which should be an
96 existing entry in ARGZ; if BEFORE is NULL, ENTRY is appended to the end.
97 Since ARGZ's first entry is the same as ARGZ, argz_insert (ARGZ, ARGZ_LEN,
98 ARGZ, ENTRY) will insert ENTRY at the beginning of ARGZ. If BEFORE is not
99 in ARGZ, EINVAL is returned, else if memory can't be allocated for the new
100 ARGZ, ENOMEM is returned, else 0. */
102 extern error_t argz_insert (char **restrict __argz,
103 size_t *restrict __argz_len,
104 char *restrict __before,
105 const char *restrict __entry);
107 /* Replace any occurrences of the string STR in ARGZ with WITH, reallocating
108 ARGZ as necessary. If REPLACE_COUNT is non-zero, *REPLACE_COUNT will be
109 incremented by number of replacements performed. */
111 extern error_t argz_replace (char **restrict __argz,
112 size_t *restrict __argz_len,
113 const char *restrict str,
114 const char *restrict __with,
115 unsigned int *restrict __replace_count);
117 /* Returns the next entry in ARGZ & ARGZ_LEN after ENTRY, or NULL if there
118 are no more. If entry is NULL, then the first entry is returned. This
119 behavior allows two convenient iteration styles:
122 while ((entry = argz_next (argz, argz_len, entry)))
128 for (entry = argz; entry; entry = argz_next (argz, argz_len, entry))
132 extern char *argz_next (const char *restrict __argz, size_t __argz_len,
133 const char *restrict __entry);
135 #ifdef __USE_EXTERN_INLINES
136 __extern_inline char *
137 __NTH (argz_next (const char *__argz, size_t __argz_len,
138 const char *__entry))
142 if (__entry < __argz + __argz_len)
143 __entry = strchr (__entry, '\0') + 1;
145 return __entry >= __argz + __argz_len ? (char *) NULL : (char *) __entry;
148 return __argz_len > 0 ? (char *) __argz : 0;
150 __extern_inline char *
151 __NTH (argz_next (const char *__argz, size_t __argz_len,
152 const char *__entry))
154 return argz_next (__argz, __argz_len, __entry);
156 #endif /* Use extern inlines. */