]>
Commit | Line | Data |
---|---|---|
392d7920 | 1 | /* Routines for dealing with '\0' separated arg vectors. |
568035b7 | 2 | Copyright (C) 1995-2013 Free Software Foundation, Inc. |
41bdb6e2 | 3 | This file is part of the GNU C Library. |
392d7920 | 4 | |
54d79e99 | 5 | The GNU C Library is free software; you can redistribute it and/or |
41bdb6e2 AJ |
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. | |
392d7920 | 9 | |
54d79e99 UD |
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 | |
392d7920 | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
41bdb6e2 | 13 | Lesser General Public License for more details. |
392d7920 | 14 | |
41bdb6e2 | 15 | You should have received a copy of the GNU Lesser General Public |
59ba27a6 PE |
16 | License along with the GNU C Library; if not, see |
17 | <http://www.gnu.org/licenses/>. */ | |
392d7920 | 18 | |
5107cf1d UD |
19 | #ifndef _ARGZ_H |
20 | #define _ARGZ_H 1 | |
7a12c6bb RM |
21 | |
22 | #include <features.h> | |
23 | ||
d1a2b102 MB |
24 | #define __need_error_t |
25 | #include <errno.h> | |
392d7920 RM |
26 | #include <string.h> /* Need size_t, and strchr is called below. */ |
27 | ||
d1a2b102 MB |
28 | #ifndef __error_t_defined |
29 | typedef int error_t; | |
30 | #endif | |
31 | ||
7a12c6bb RM |
32 | |
33 | __BEGIN_DECLS | |
34 | ||
392d7920 RM |
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. */ | |
a784e502 | 38 | extern error_t __argz_create (char *const __argv[], char **__restrict __argz, |
c1422e5b | 39 | size_t *__restrict __len) __THROW; |
a784e502 | 40 | extern error_t argz_create (char *const __argv[], char **__restrict __argz, |
c1422e5b | 41 | size_t *__restrict __len) __THROW; |
7a12c6bb RM |
42 | |
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. */ | |
a784e502 | 47 | extern error_t __argz_create_sep (const char *__restrict __string, |
c1422e5b UD |
48 | int __sep, char **__restrict __argz, |
49 | size_t *__restrict __len) __THROW; | |
a784e502 | 50 | extern error_t argz_create_sep (const char *__restrict __string, |
c1422e5b UD |
51 | int __sep, char **__restrict __argz, |
52 | size_t *__restrict __len) __THROW; | |
392d7920 RM |
53 | |
54 | /* Returns the number of strings in ARGZ. */ | |
a784e502 | 55 | extern size_t __argz_count (const char *__argz, size_t __len) |
e656498e | 56 | __THROW __attribute_pure__; |
a784e502 | 57 | extern size_t argz_count (const char *__argz, size_t __len) |
e656498e | 58 | __THROW __attribute_pure__; |
392d7920 RM |
59 | |
60 | /* Puts pointers to each string in ARGZ into ARGV, which must be large enough | |
61 | to hold them all. */ | |
a784e502 | 62 | extern void __argz_extract (const char *__restrict __argz, size_t __len, |
c1422e5b | 63 | char **__restrict __argv) __THROW; |
a784e502 | 64 | extern void argz_extract (const char *__restrict __argz, size_t __len, |
c1422e5b | 65 | char **__restrict __argv) __THROW; |
392d7920 RM |
66 | |
67 | /* Make '\0' separated arg vector ARGZ printable by converting all the '\0's | |
68 | except the last into the character SEP. */ | |
c1422e5b UD |
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; | |
392d7920 RM |
71 | |
72 | /* Append BUF, of length BUF_LEN to the argz vector in ARGZ & ARGZ_LEN. */ | |
c1422e5b UD |
73 | extern error_t __argz_append (char **__restrict __argz, |
74 | size_t *__restrict __argz_len, | |
a784e502 | 75 | const char *__restrict __buf, size_t __buf_len) |
c1422e5b UD |
76 | __THROW; |
77 | extern error_t argz_append (char **__restrict __argz, | |
78 | size_t *__restrict __argz_len, | |
a784e502 | 79 | const char *__restrict __buf, size_t __buf_len) |
c1422e5b | 80 | __THROW; |
392d7920 RM |
81 | |
82 | /* Append STR to the argz vector in ARGZ & ARGZ_LEN. */ | |
c1422e5b UD |
83 | extern error_t __argz_add (char **__restrict __argz, |
84 | size_t *__restrict __argz_len, | |
a784e502 | 85 | const char *__restrict __str) __THROW; |
c1422e5b UD |
86 | extern error_t argz_add (char **__restrict __argz, |
87 | size_t *__restrict __argz_len, | |
a784e502 | 88 | const char *__restrict __str) __THROW; |
392d7920 | 89 | |
e4cf5070 UD |
90 | /* Append SEP separated list in STRING to the argz vector in ARGZ & |
91 | ARGZ_LEN. */ | |
c1422e5b UD |
92 | extern error_t __argz_add_sep (char **__restrict __argz, |
93 | size_t *__restrict __argz_len, | |
a784e502 | 94 | const char *__restrict __string, int __delim) |
c1422e5b UD |
95 | __THROW; |
96 | extern error_t argz_add_sep (char **__restrict __argz, | |
97 | size_t *__restrict __argz_len, | |
a784e502 | 98 | const char *__restrict __string, int __delim) |
c1422e5b | 99 | __THROW; |
e4cf5070 | 100 | |
392d7920 | 101 | /* Delete ENTRY from ARGZ & ARGZ_LEN, if it appears there. */ |
c1422e5b UD |
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; | |
392d7920 RM |
108 | |
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. */ | |
c1422e5b UD |
115 | extern error_t __argz_insert (char **__restrict __argz, |
116 | size_t *__restrict __argz_len, | |
117 | char *__restrict __before, | |
a784e502 | 118 | const char *__restrict __entry) __THROW; |
c1422e5b UD |
119 | extern error_t argz_insert (char **__restrict __argz, |
120 | size_t *__restrict __argz_len, | |
121 | char *__restrict __before, | |
a784e502 | 122 | const char *__restrict __entry) __THROW; |
d705269e | 123 | |
49c091e5 | 124 | /* Replace any occurrences of the string STR in ARGZ with WITH, reallocating |
d705269e UD |
125 | ARGZ as necessary. If REPLACE_COUNT is non-zero, *REPLACE_COUNT will be |
126 | incremented by number of replacements performed. */ | |
a6ff34d7 UD |
127 | extern error_t __argz_replace (char **__restrict __argz, |
128 | size_t *__restrict __argz_len, | |
a784e502 UD |
129 | const char *__restrict __str, |
130 | const char *__restrict __with, | |
a6ff34d7 UD |
131 | unsigned int *__restrict __replace_count); |
132 | extern error_t argz_replace (char **__restrict __argz, | |
133 | size_t *__restrict __argz_len, | |
a784e502 UD |
134 | const char *__restrict __str, |
135 | const char *__restrict __with, | |
a6ff34d7 | 136 | unsigned int *__restrict __replace_count); |
392d7920 RM |
137 | \f |
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: | |
141 | ||
142 | char *entry = 0; | |
7a12c6bb | 143 | while ((entry = argz_next (argz, argz_len, entry))) |
392d7920 RM |
144 | ...; |
145 | ||
146 | or | |
147 | ||
148 | char *entry; | |
149 | for (entry = argz; entry; entry = argz_next (argz, argz_len, entry)) | |
150 | ...; | |
151 | */ | |
a784e502 UD |
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; | |
7a12c6bb | 156 | |
0c6cee5d | 157 | #ifdef __USE_EXTERN_INLINES |
b037a293 | 158 | __extern_inline char * |
a784e502 UD |
159 | __NTH (__argz_next (const char *__argz, size_t __argz_len, |
160 | const char *__entry)) | |
392d7920 | 161 | { |
23396375 | 162 | if (__entry) |
7a12c6bb | 163 | { |
23396375 UD |
164 | if (__entry < __argz + __argz_len) |
165 | __entry = strchr (__entry, '\0') + 1; | |
7a12c6bb | 166 | |
2604afb1 | 167 | return __entry >= __argz + __argz_len ? (char *) NULL : (char *) __entry; |
7a12c6bb | 168 | } |
392d7920 | 169 | else |
62ee0979 | 170 | return __argz_len > 0 ? (char *) __argz : 0; |
392d7920 | 171 | } |
b037a293 | 172 | __extern_inline char * |
a784e502 UD |
173 | __NTH (argz_next (const char *__argz, size_t __argz_len, |
174 | const char *__entry)) | |
7a12c6bb | 175 | { |
23396375 | 176 | return __argz_next (__argz, __argz_len, __entry); |
7a12c6bb | 177 | } |
0c6cee5d | 178 | #endif /* Use extern inlines. */ |
392d7920 | 179 | |
92f1da4d UD |
180 | __END_DECLS |
181 | ||
2c6fe0bd | 182 | #endif /* argz.h */ |