1 /* Routines for dealing with '\0' separated arg vectors.
2 Copyright (C) 1995, 96, 97, 98, 99, 2000 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. */
24 #define __need_error_t
26 #include <string.h> /* Need size_t, and strchr is called below. */
29 # define __const const
32 #ifndef __error_t_defined
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
)
60 __THROW __attribute_pure__
;
61 extern size_t argz_count (__const
char *__argz
, size_t __len
)
62 __THROW __attribute_pure__
;
64 /* Puts pointers to each string in ARGZ into ARGV, which must be large enough
66 extern void __argz_extract (__const
char *__restrict __argz
, size_t __len
,
67 char **__restrict __argv
) __THROW
;
68 extern void argz_extract (__const
char *__restrict __argz
, size_t __len
,
69 char **__restrict __argv
) __THROW
;
71 /* Make '\0' separated arg vector ARGZ printable by converting all the '\0's
72 except the last into the character SEP. */
73 extern void __argz_stringify (char *__argz
, size_t __len
, int __sep
) __THROW
;
74 extern void argz_stringify (char *__argz
, size_t __len
, int __sep
) __THROW
;
76 /* Append BUF, of length BUF_LEN to the argz vector in ARGZ & ARGZ_LEN. */
77 extern error_t
__argz_append (char **__restrict __argz
,
78 size_t *__restrict __argz_len
,
79 __const
char *__restrict __buf
, size_t _buf_len
)
81 extern error_t
argz_append (char **__restrict __argz
,
82 size_t *__restrict __argz_len
,
83 __const
char *__restrict __buf
, size_t __buf_len
)
86 /* Append STR to the argz vector in ARGZ & ARGZ_LEN. */
87 extern error_t
__argz_add (char **__restrict __argz
,
88 size_t *__restrict __argz_len
,
89 __const
char *__restrict __str
) __THROW
;
90 extern error_t
argz_add (char **__restrict __argz
,
91 size_t *__restrict __argz_len
,
92 __const
char *__restrict __str
) __THROW
;
94 /* Append SEP separated list in STRING to the argz vector in ARGZ &
96 extern error_t
__argz_add_sep (char **__restrict __argz
,
97 size_t *__restrict __argz_len
,
98 __const
char *__restrict __string
, int __delim
)
100 extern error_t
argz_add_sep (char **__restrict __argz
,
101 size_t *__restrict __argz_len
,
102 __const
char *__restrict __string
, int __delim
)
105 /* Delete ENTRY from ARGZ & ARGZ_LEN, if it appears there. */
106 extern void __argz_delete (char **__restrict __argz
,
107 size_t *__restrict __argz_len
,
108 char *__restrict __entry
) __THROW
;
109 extern void argz_delete (char **__restrict __argz
,
110 size_t *__restrict __argz_len
,
111 char *__restrict __entry
) __THROW
;
113 /* Insert ENTRY into ARGZ & ARGZ_LEN before BEFORE, which should be an
114 existing entry in ARGZ; if BEFORE is NULL, ENTRY is appended to the end.
115 Since ARGZ's first entry is the same as ARGZ, argz_insert (ARGZ, ARGZ_LEN,
116 ARGZ, ENTRY) will insert ENTRY at the beginning of ARGZ. If BEFORE is not
117 in ARGZ, EINVAL is returned, else if memory can't be allocated for the new
118 ARGZ, ENOMEM is returned, else 0. */
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
;
123 extern error_t
argz_insert (char **__restrict __argz
,
124 size_t *__restrict __argz_len
,
125 char *__restrict __before
,
126 __const
char *__restrict __entry
) __THROW
;
128 /* Replace any occurrences of the string STR in ARGZ with WITH, reallocating
129 ARGZ as necessary. If REPLACE_COUNT is non-zero, *REPLACE_COUNT will be
130 incremented by number of replacements performed. */
131 extern error_t
__argz_replace (char **__restrict __argz
,
132 size_t *__restrict __argz_len
,
133 __const
char *__restrict __str
,
134 __const
char *__restrict __with
,
135 unsigned int *__restrict __replace_count
);
136 extern error_t
argz_replace (char **__restrict __argz
,
137 size_t *__restrict __argz_len
,
138 __const
char *__restrict __str
,
139 __const
char *__restrict __with
,
140 unsigned int *__restrict __replace_count
);
142 /* Returns the next entry in ARGZ & ARGZ_LEN after ENTRY, or NULL if there
143 are no more. If entry is NULL, then the first entry is returned. This
144 behavior allows two convenient iteration styles:
147 while ((entry = argz_next (argz, argz_len, entry)))
153 for (entry = argz; entry; entry = argz_next (argz, argz_len, entry))
156 extern char *__argz_next (__const
char *__restrict __argz
, size_t __argz_len
,
157 __const
char *__restrict __entry
) __THROW
;
158 extern char *argz_next (__const
char *__restrict __argz
, size_t __argz_len
,
159 __const
char *__restrict __entry
) __THROW
;
161 #ifdef __USE_EXTERN_INLINES
163 __argz_next (__const
char *__argz
, size_t __argz_len
,
164 __const
char *__entry
) __THROW
168 if (__entry
< __argz
+ __argz_len
)
169 __entry
= strchr (__entry
, '\0') + 1;
171 return __entry
>= __argz
+ __argz_len
? (char *) NULL
: (char *) __entry
;
174 return __argz_len
> 0 ? (char *) __argz
: 0;
177 argz_next (__const
char *__argz
, size_t __argz_len
,
178 __const
char *__entry
) __THROW
180 return __argz_next (__argz
, __argz_len
, __entry
);
182 #endif /* Use extern inlines. */