Update.
[glibc.git] / string / argz.h
bloba90da9a1473cc4fe4a7a6ef28a4f98394757957f
1 /* Routines for dealing with '\0' separated arg vectors.
2 Copyright (C) 1995, 96, 97, 98, 99 Free Software Foundation, Inc.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public License as
6 published by the Free Software Foundation; either version 2 of the
7 License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public
15 License along with the GNU C Library; see the file COPYING.LIB. If not,
16 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 Boston, MA 02111-1307, USA. */
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 __const
29 # define __const const
30 #endif
32 #ifndef __error_t_defined
33 typedef int error_t;
34 #endif
37 __BEGIN_DECLS
39 /* Make a '\0' separated arg vector from a unix argv vector, returning it in
40 ARGZ, and the total length in LEN. If a memory allocation error occurs,
41 ENOMEM is returned, otherwise 0. The result can be destroyed using free. */
42 extern error_t __argz_create (char *__const __argv[], char **__restrict __argz,
43 size_t *__restrict __len) __THROW;
44 extern error_t argz_create (char *__const __argv[], char **__restrict __argz,
45 size_t *__restrict __len) __THROW;
47 /* Make a '\0' separated arg vector from a SEP separated list in
48 STRING, returning it in ARGZ, and the total length in LEN. If a
49 memory allocation error occurs, ENOMEM is returned, otherwise 0.
50 The result can be destroyed using free. */
51 extern error_t __argz_create_sep (__const char *__restrict __string,
52 int __sep, char **__restrict __argz,
53 size_t *__restrict __len) __THROW;
54 extern error_t argz_create_sep (__const char *__restrict __string,
55 int __sep, char **__restrict __argz,
56 size_t *__restrict __len) __THROW;
58 /* Returns the number of strings in ARGZ. */
59 extern size_t __argz_count (__const char *__argz, size_t __len) __THROW;
60 extern size_t argz_count (__const char *__argz, size_t __len) __THROW;
62 /* Puts pointers to each string in ARGZ into ARGV, which must be large enough
63 to hold them all. */
64 extern void __argz_extract (__const char *__restrict __argz, size_t __len,
65 char **__restrict __argv) __THROW;
66 extern void argz_extract (__const char *__restrict __argz, size_t __len,
67 char **__restrict __argv) __THROW;
69 /* Make '\0' separated arg vector ARGZ printable by converting all the '\0's
70 except the last into the character SEP. */
71 extern void __argz_stringify (char *__argz, size_t __len, int __sep) __THROW;
72 extern void argz_stringify (char *__argz, size_t __len, int __sep) __THROW;
74 /* Append BUF, of length BUF_LEN to the argz vector in ARGZ & ARGZ_LEN. */
75 extern error_t __argz_append (char **__restrict __argz,
76 size_t *__restrict __argz_len,
77 __const char *__restrict __buf, size_t _buf_len)
78 __THROW;
79 extern error_t argz_append (char **__restrict __argz,
80 size_t *__restrict __argz_len,
81 __const char *__restrict __buf, size_t __buf_len)
82 __THROW;
84 /* Append STR to the argz vector in ARGZ & ARGZ_LEN. */
85 extern error_t __argz_add (char **__restrict __argz,
86 size_t *__restrict __argz_len,
87 __const char *__restrict __str) __THROW;
88 extern error_t argz_add (char **__restrict __argz,
89 size_t *__restrict __argz_len,
90 __const char *__restrict __str) __THROW;
92 /* Append SEP separated list in STRING to the argz vector in ARGZ &
93 ARGZ_LEN. */
94 extern error_t __argz_add_sep (char **__restrict __argz,
95 size_t *__restrict __argz_len,
96 __const char *__restrict __string, int __delim)
97 __THROW;
98 extern error_t argz_add_sep (char **__restrict __argz,
99 size_t *__restrict __argz_len,
100 __const char *__restrict __string, int __delim)
101 __THROW;
103 /* Delete ENTRY from ARGZ & ARGZ_LEN, if it appears there. */
104 extern void __argz_delete (char **__restrict __argz,
105 size_t *__restrict __argz_len,
106 char *__restrict __entry) __THROW;
107 extern void argz_delete (char **__restrict __argz,
108 size_t *__restrict __argz_len,
109 char *__restrict __entry) __THROW;
111 /* Insert ENTRY into ARGZ & ARGZ_LEN before BEFORE, which should be an
112 existing entry in ARGZ; if BEFORE is NULL, ENTRY is appended to the end.
113 Since ARGZ's first entry is the same as ARGZ, argz_insert (ARGZ, ARGZ_LEN,
114 ARGZ, ENTRY) will insert ENTRY at the beginning of ARGZ. If BEFORE is not
115 in ARGZ, EINVAL is returned, else if memory can't be allocated for the new
116 ARGZ, ENOMEM is returned, else 0. */
117 extern error_t __argz_insert (char **__restrict __argz,
118 size_t *__restrict __argz_len,
119 char *__restrict __before,
120 __const char *__restrict __entry) __THROW;
121 extern error_t argz_insert (char **__restrict __argz,
122 size_t *__restrict __argz_len,
123 char *__restrict __before,
124 __const char *__restrict __entry) __THROW;
126 /* Replace any occurances of the string STR in ARGZ with WITH, reallocating
127 ARGZ as necessary. If REPLACE_COUNT is non-zero, *REPLACE_COUNT will be
128 incremented by number of replacements performed. */
129 extern error_t __argz_replace (char **__restrict __argz,
130 size_t *__restrict __argz_len,
131 __const char *__restrict __str,
132 __const char *__restrict __with,
133 unsigned int *__restrict __replace_count);
134 extern error_t argz_replace (char **__restrict __argz,
135 size_t *__restrict __argz_len,
136 __const char *__restrict __str,
137 __const char *__restrict __with,
138 unsigned int *__restrict __replace_count);
140 /* Returns the next entry in ARGZ & ARGZ_LEN after ENTRY, or NULL if there
141 are no more. If entry is NULL, then the first entry is returned. This
142 behavior allows two convenient iteration styles:
144 char *entry = 0;
145 while ((entry = argz_next (argz, argz_len, entry)))
146 ...;
150 char *entry;
151 for (entry = argz; entry; entry = argz_next (argz, argz_len, entry))
152 ...;
154 extern char *__argz_next (__const char *__restrict __argz, size_t __argz_len,
155 __const char *__restrict __entry) __THROW;
156 extern char *argz_next (__const char *__restrict __argz, size_t __argz_len,
157 __const char *__restrict __entry) __THROW;
159 #ifdef __USE_EXTERN_INLINES
160 extern inline char *
161 __argz_next (__const char *__argz, size_t __argz_len,
162 __const char *__entry) __THROW
164 if (__entry)
166 if (__entry < __argz + __argz_len)
167 __entry = strchr (__entry, '\0') + 1;
169 return __entry >= __argz + __argz_len ? (char *) NULL : (char *) __entry;
171 else
172 return __argz_len > 0 ? (char *) __argz : 0;
174 extern inline char *
175 argz_next (__const char *__argz, size_t __argz_len,
176 __const char *__entry) __THROW
178 return __argz_next (__argz, __argz_len, __entry);
180 #endif /* Use extern inlines. */
182 __END_DECLS
184 #endif /* argz.h */