mountlist: Use Linux code on Android.
[gnulib.git] / lib / argz.in.h
blobab4f1a7004701a5eebfbb66b0fac0f5569b3e4e0
1 /* Routines for dealing with '\0' separated arg vectors.
2 Copyright (C) 1995-2000, 2004, 2007, 2009-2019 Free Software Foundation,
3 Inc.
4 This file is part of the GNU C Library.
6 This program is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <https://www.gnu.org/licenses/>. */
19 #ifndef _ARGZ_H
20 #define _ARGZ_H 1
23 #define __need_error_t
24 #include <errno.h>
25 #include <string.h> /* Need size_t, and strchr is called below. */
27 #ifndef const
28 # define const const
29 #endif
31 #ifndef __error_t_defined
32 typedef int error_t;
33 #endif
37 /* Make a '\0' separated arg vector from a unix argv vector, returning it in
38 ARGZ, and the total length in LEN. If a memory allocation error occurs,
39 ENOMEM is returned, otherwise 0. The result can be destroyed using free. */
41 extern error_t argz_create (char *const __argv[], char **restrict __argz,
42 size_t *restrict __len);
44 /* Make a '\0' separated arg vector from a SEP separated list in
45 STRING, returning it in ARGZ, and the total length in LEN. If a
46 memory allocation error occurs, ENOMEM is returned, otherwise 0.
47 The result can be destroyed using free. */
49 extern error_t argz_create_sep (const char *restrict string,
50 int __sep, char **restrict __argz,
51 size_t *restrict __len);
53 /* Returns the number of strings in ARGZ. */
55 extern size_t argz_count (const char *__argz, size_t __len)
58 /* Puts pointers to each string in ARGZ into ARGV, which must be large enough
59 to hold them all. */
61 extern void argz_extract (const char *restrict __argz, size_t __len,
62 char **restrict __argv);
64 /* Make '\0' separated arg vector ARGZ printable by converting all the '\0's
65 except the last into the character SEP. */
67 extern void argz_stringify (char *__argz, size_t __len, int __sep);
69 /* Append BUF, of length BUF_LEN to the argz vector in ARGZ & ARGZ_LEN. */
71 extern error_t argz_append (char **restrict __argz,
72 size_t *restrict __argz_len,
73 const char *restrict __buf, size_t __buf_len)
76 /* Append STR to the argz vector in ARGZ & ARGZ_LEN. */
78 extern error_t argz_add (char **restrict __argz,
79 size_t *restrict __argz_len,
80 const char *restrict str);
82 /* Append SEP separated list in STRING to the argz vector in ARGZ &
83 ARGZ_LEN. */
85 extern error_t argz_add_sep (char **restrict __argz,
86 size_t *restrict __argz_len,
87 const char *restrict string, int __delim)
90 /* Delete ENTRY from ARGZ & ARGZ_LEN, if it appears there. */
92 extern void argz_delete (char **restrict __argz,
93 size_t *restrict __argz_len,
94 char *restrict __entry);
96 /* Insert ENTRY into ARGZ & ARGZ_LEN before BEFORE, which should be an
97 existing entry in ARGZ; if BEFORE is NULL, ENTRY is appended to the end.
98 Since ARGZ's first entry is the same as ARGZ, argz_insert (ARGZ, ARGZ_LEN,
99 ARGZ, ENTRY) will insert ENTRY at the beginning of ARGZ. If BEFORE is not
100 in ARGZ, EINVAL is returned, else if memory can't be allocated for the new
101 ARGZ, ENOMEM is returned, else 0. */
103 extern error_t argz_insert (char **restrict __argz,
104 size_t *restrict __argz_len,
105 char *restrict __before,
106 const char *restrict __entry);
108 /* Replace any occurrences of the string STR in ARGZ with WITH, reallocating
109 ARGZ as necessary. If REPLACE_COUNT is non-zero, *REPLACE_COUNT will be
110 incremented by number of replacements performed. */
112 extern error_t argz_replace (char **restrict __argz,
113 size_t *restrict __argz_len,
114 const char *restrict str,
115 const char *restrict __with,
116 unsigned int *restrict __replace_count);
118 /* Returns the next entry in ARGZ & ARGZ_LEN after ENTRY, or NULL if there
119 are no more. If entry is NULL, then the first entry is returned. This
120 behavior allows two convenient iteration styles:
122 char *entry = 0;
123 while ((entry = argz_next (argz, argz_len, entry)))
124 ...;
128 char *entry;
129 for (entry = argz; entry; entry = argz_next (argz, argz_len, entry))
130 ...;
133 extern char *argz_next (const char *restrict __argz, size_t __argz_len,
134 const char *restrict __entry);
136 #ifdef __USE_EXTERN_INLINES
137 __extern_inline char *
138 __NTH (argz_next (const char *__argz, size_t __argz_len,
139 const char *__entry))
141 if (__entry)
143 if (__entry < __argz + __argz_len)
144 __entry = strchr (__entry, '\0') + 1;
146 return __entry >= __argz + __argz_len ? (char *) NULL : (char *) __entry;
148 else
149 return __argz_len > 0 ? (char *) __argz : 0;
151 __extern_inline char *
152 __NTH (argz_next (const char *__argz, size_t __argz_len,
153 const char *__entry))
155 return argz_next (__argz, __argz_len, __entry);
157 #endif /* Use extern inlines. */
160 #endif /* argz.h */