Mention BZ #14229 in NEWS
[glibc.git] / string / argz.h
blob5a54a35ad24afa03e4d47e5ca315c7c2a8ef3ff3
1 /* Routines for dealing with '\0' separated arg vectors.
2 Copyright (C) 1995-2000,2004,2007,2012 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library 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 GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
19 #ifndef _ARGZ_H
20 #define _ARGZ_H 1
22 #include <features.h>
24 #define __need_error_t
25 #include <errno.h>
26 #include <string.h> /* Need size_t, and strchr is called below. */
28 #ifndef __error_t_defined
29 typedef int error_t;
30 #endif
33 __BEGIN_DECLS
35 /* Make a '\0' separated arg vector from a unix argv vector, returning it in
36 ARGZ, and the total length in LEN. If a memory allocation error occurs,
37 ENOMEM is returned, otherwise 0. The result can be destroyed using free. */
38 extern error_t __argz_create (char *const __argv[], char **__restrict __argz,
39 size_t *__restrict __len) __THROW;
40 extern error_t argz_create (char *const __argv[], char **__restrict __argz,
41 size_t *__restrict __len) __THROW;
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. */
47 extern error_t __argz_create_sep (const char *__restrict __string,
48 int __sep, char **__restrict __argz,
49 size_t *__restrict __len) __THROW;
50 extern error_t argz_create_sep (const char *__restrict __string,
51 int __sep, char **__restrict __argz,
52 size_t *__restrict __len) __THROW;
54 /* Returns the number of strings in ARGZ. */
55 extern size_t __argz_count (const char *__argz, size_t __len)
56 __THROW __attribute_pure__;
57 extern size_t argz_count (const char *__argz, size_t __len)
58 __THROW __attribute_pure__;
60 /* Puts pointers to each string in ARGZ into ARGV, which must be large enough
61 to hold them all. */
62 extern void __argz_extract (const char *__restrict __argz, size_t __len,
63 char **__restrict __argv) __THROW;
64 extern void argz_extract (const char *__restrict __argz, size_t __len,
65 char **__restrict __argv) __THROW;
67 /* Make '\0' separated arg vector ARGZ printable by converting all the '\0's
68 except the last into the character SEP. */
69 extern void __argz_stringify (char *__argz, size_t __len, int __sep) __THROW;
70 extern void argz_stringify (char *__argz, size_t __len, int __sep) __THROW;
72 /* Append BUF, of length BUF_LEN to the argz vector in ARGZ & ARGZ_LEN. */
73 extern error_t __argz_append (char **__restrict __argz,
74 size_t *__restrict __argz_len,
75 const char *__restrict __buf, size_t __buf_len)
76 __THROW;
77 extern error_t argz_append (char **__restrict __argz,
78 size_t *__restrict __argz_len,
79 const char *__restrict __buf, size_t __buf_len)
80 __THROW;
82 /* Append STR to the argz vector in ARGZ & ARGZ_LEN. */
83 extern error_t __argz_add (char **__restrict __argz,
84 size_t *__restrict __argz_len,
85 const char *__restrict __str) __THROW;
86 extern error_t argz_add (char **__restrict __argz,
87 size_t *__restrict __argz_len,
88 const char *__restrict __str) __THROW;
90 /* Append SEP separated list in STRING to the argz vector in ARGZ &
91 ARGZ_LEN. */
92 extern error_t __argz_add_sep (char **__restrict __argz,
93 size_t *__restrict __argz_len,
94 const char *__restrict __string, int __delim)
95 __THROW;
96 extern error_t argz_add_sep (char **__restrict __argz,
97 size_t *__restrict __argz_len,
98 const char *__restrict __string, int __delim)
99 __THROW;
101 /* Delete ENTRY from ARGZ & ARGZ_LEN, if it appears there. */
102 extern void __argz_delete (char **__restrict __argz,
103 size_t *__restrict __argz_len,
104 char *__restrict __entry) __THROW;
105 extern void argz_delete (char **__restrict __argz,
106 size_t *__restrict __argz_len,
107 char *__restrict __entry) __THROW;
109 /* Insert ENTRY into ARGZ & ARGZ_LEN before BEFORE, which should be an
110 existing entry in ARGZ; if BEFORE is NULL, ENTRY is appended to the end.
111 Since ARGZ's first entry is the same as ARGZ, argz_insert (ARGZ, ARGZ_LEN,
112 ARGZ, ENTRY) will insert ENTRY at the beginning of ARGZ. If BEFORE is not
113 in ARGZ, EINVAL is returned, else if memory can't be allocated for the new
114 ARGZ, ENOMEM is returned, else 0. */
115 extern error_t __argz_insert (char **__restrict __argz,
116 size_t *__restrict __argz_len,
117 char *__restrict __before,
118 const char *__restrict __entry) __THROW;
119 extern error_t argz_insert (char **__restrict __argz,
120 size_t *__restrict __argz_len,
121 char *__restrict __before,
122 const char *__restrict __entry) __THROW;
124 /* Replace any occurrences of the string STR in ARGZ with WITH, reallocating
125 ARGZ as necessary. If REPLACE_COUNT is non-zero, *REPLACE_COUNT will be
126 incremented by number of replacements performed. */
127 extern error_t __argz_replace (char **__restrict __argz,
128 size_t *__restrict __argz_len,
129 const char *__restrict __str,
130 const char *__restrict __with,
131 unsigned int *__restrict __replace_count);
132 extern error_t argz_replace (char **__restrict __argz,
133 size_t *__restrict __argz_len,
134 const char *__restrict __str,
135 const char *__restrict __with,
136 unsigned int *__restrict __replace_count);
138 /* Returns the next entry in ARGZ & ARGZ_LEN after ENTRY, or NULL if there
139 are no more. If entry is NULL, then the first entry is returned. This
140 behavior allows two convenient iteration styles:
142 char *entry = 0;
143 while ((entry = argz_next (argz, argz_len, entry)))
144 ...;
148 char *entry;
149 for (entry = argz; entry; entry = argz_next (argz, argz_len, entry))
150 ...;
152 extern char *__argz_next (const char *__restrict __argz, size_t __argz_len,
153 const char *__restrict __entry) __THROW;
154 extern char *argz_next (const char *__restrict __argz, size_t __argz_len,
155 const char *__restrict __entry) __THROW;
157 #ifdef __USE_EXTERN_INLINES
158 __extern_inline char *
159 __NTH (__argz_next (const char *__argz, size_t __argz_len,
160 const char *__entry))
162 if (__entry)
164 if (__entry < __argz + __argz_len)
165 __entry = strchr (__entry, '\0') + 1;
167 return __entry >= __argz + __argz_len ? (char *) NULL : (char *) __entry;
169 else
170 return __argz_len > 0 ? (char *) __argz : 0;
172 __extern_inline char *
173 __NTH (argz_next (const char *__argz, size_t __argz_len,
174 const char *__entry))
176 return __argz_next (__argz, __argz_len, __entry);
178 #endif /* Use extern inlines. */
180 __END_DECLS
182 #endif /* argz.h */