]> git.ipfire.org Git - thirdparty/glibc.git/blob - string/argz.h
update from main archive 961105
[thirdparty/glibc.git] / string / argz.h
1 /* Routines for dealing with '\0' separated arg vectors.
2 Copyright (C) 1995, 1996 Free Software Foundation, Inc.
3 Written by Miles Bader <miles@gnu.ai.mit.edu>
4
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License as
7 published by the Free Software Foundation; either version 2, or (at
8 your option) any later version.
9
10 This program is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
18
19 #ifndef __ARGZ_H__
20
21 #define __ARGZ_H__ 1
22 #include <features.h>
23
24 #include <errno.h> /* Define error_t. */
25 #include <string.h> /* Need size_t, and strchr is called below. */
26
27
28 __BEGIN_DECLS
29
30 /* Make a '\0' separated arg vector from a unix argv vector, returning it in
31 ARGZ, and the total length in LEN. If a memory allocation error occurs,
32 ENOMEM is returned, otherwise 0. The result can be destroyed using free. */
33 extern error_t __argz_create __P ((char *__const __argv[], char **__argz,
34 size_t *__len));
35 extern error_t argz_create __P ((char *__const __argv[], char **__argz,
36 size_t *__len));
37
38 /* Make a '\0' separated arg vector from a SEP separated list in
39 STRING, returning it in ARGZ, and the total length in LEN. If a
40 memory allocation error occurs, ENOMEM is returned, otherwise 0.
41 The result can be destroyed using free. */
42 extern error_t __argz_create_sep __P ((__const char *__string, int __sep,
43 char **__argz, size_t *__len));
44 extern error_t argz_create_sep __P ((__const char *__string, int __sep,
45 char **__argz, size_t *__len));
46
47 /* Returns the number of strings in ARGZ. */
48 extern size_t __argz_count __P ((__const char *__argz, size_t __len));
49 extern size_t argz_count __P ((__const char *__argz, size_t __len));
50
51 /* Puts pointers to each string in ARGZ into ARGV, which must be large enough
52 to hold them all. */
53 extern void __argz_extract __P ((char *__argz, size_t __len, char **__argv));
54 extern void argz_extract __P ((char *__argz, size_t __len, char **__argv));
55
56 /* Make '\0' separated arg vector ARGZ printable by converting all the '\0's
57 except the last into the character SEP. */
58 extern void __argz_stringify __P ((char *__argz, size_t __len, int __sep));
59 extern void argz_stringify __P ((char *__argz, size_t __len, int __sep));
60
61 /* Append BUF, of length BUF_LEN to the argz vector in ARGZ & ARGZ_LEN. */
62 extern error_t __argz_append __P ((char **__argz, size_t *__argz_len,
63 __const char *__buf, size_t _buf_len));
64 extern error_t argz_append __P ((char **__argz, size_t *__argz_len,
65 __const char *__buf, size_t __buf_len));
66
67 /* Append STR to the argz vector in ARGZ & ARGZ_LEN. */
68 extern error_t __argz_add __P ((char **__argz, size_t *__argz_len,
69 __const char *__str));
70 extern error_t argz_add __P ((char **__argz, size_t *__argz_len,
71 __const char *__str));
72
73 /* Delete ENTRY from ARGZ & ARGZ_LEN, if it appears there. */
74 extern void __argz_delete __P ((char **__argz, size_t *__argz_len,
75 char *__entry));
76 extern void argz_delete __P ((char **__argz, size_t *__argz_len,
77 char *__entry));
78
79 /* Insert ENTRY into ARGZ & ARGZ_LEN before BEFORE, which should be an
80 existing entry in ARGZ; if BEFORE is NULL, ENTRY is appended to the end.
81 Since ARGZ's first entry is the same as ARGZ, argz_insert (ARGZ, ARGZ_LEN,
82 ARGZ, ENTRY) will insert ENTRY at the beginning of ARGZ. If BEFORE is not
83 in ARGZ, EINVAL is returned, else if memory can't be allocated for the new
84 ARGZ, ENOMEM is returned, else 0. */
85 extern error_t __argz_insert __P ((char **__argz, size_t *__argz_len,
86 char *__before, __const char *__entry));
87 extern error_t argz_insert __P ((char **__argz, size_t *__argz_len,
88 char *__before, __const char *__entry));
89 \f
90 /* Returns the next entry in ARGZ & ARGZ_LEN after ENTRY, or NULL if there
91 are no more. If entry is NULL, then the first entry is returned. This
92 behavior allows two convenient iteration styles:
93
94 char *entry = 0;
95 while ((entry = argz_next (argz, argz_len, entry)))
96 ...;
97
98 or
99
100 char *entry;
101 for (entry = argz; entry; entry = argz_next (argz, argz_len, entry))
102 ...;
103 */
104 extern char *__argz_next __P ((char *argz, size_t __argz_len,
105 __const char *entry));
106 extern char *argz_next __P ((char *argz, size_t __argz_len,
107 __const char *entry));
108
109 #if defined (__OPTIMIZE__) && __GNUC__ >= 2
110 extern inline char *
111 __argz_next (char *__argz, size_t __argz_len, __const char *__entry)
112 {
113 if (__entry)
114 {
115 if (__entry < __argz + __argz_len)
116 __entry = strchr (__entry, '\0') + 1;
117
118 return __entry >= __argz + __argz_len ? NULL : (char *) __entry;
119 }
120 else
121 return __argz_len > 0 ? __argz : 0;
122 }
123 extern inline char *
124 argz_next (char *__argz, size_t __argz_len, __const char *__entry)
125 {
126 return __argz_next (__argz, __argz_len, __entry);
127 }
128 #endif /* optimizing GCC2 */
129
130 #endif /* argz.h */