source: trunk/src/emx/include/argz.h@ 1624

Last change on this file since 1624 was 1506, checked in by bird, 21 years ago

@unixroot. header reviews. ++

  • Property cvs2svn:cvs-rev set to 1.3
  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 7.2 KB
Line 
1/* argz.h,v 1.3 2004/09/14 22:27:31 bird Exp */
2/** @file
3 * GLIBC v2.3.2
4 */
5
6/* Routines for dealing with '\0' separated arg vectors.
7 Copyright (C) 1995, 96, 97, 98, 99, 2000 Free Software Foundation, Inc.
8 This file is part of the GNU C Library.
9
10 The GNU C Library is free software; you can redistribute it and/or
11 modify it under the terms of the GNU Lesser General Public
12 License as published by the Free Software Foundation; either
13 version 2.1 of the License, or (at your option) any later version.
14
15 The GNU C Library is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 Lesser General Public License for more details.
19
20 You should have received a copy of the GNU Lesser General Public
21 License along with the GNU C Library; if not, write to the Free
22 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
23 02111-1307 USA. */
24
25
26#ifndef _ARGZ_H
27#define _ARGZ_H 1
28
29#include <features.h>
30
31#define __need_error_t
32#include <errno.h>
33#include <string.h> /* Need size_t, and strchr is called below. */
34
35#ifndef __const
36# define __const const
37#endif
38
39#ifndef __error_t_defined
40typedef int error_t;
41#endif
42
43
44__BEGIN_DECLS
45
46/* Make a '\0' separated arg vector from a unix argv vector, returning it in
47 ARGZ, and the total length in LEN. If a memory allocation error occurs,
48 ENOMEM is returned, otherwise 0. The result can be destroyed using free. */
49extern error_t __argz_create (char *__const __argv[], char **__restrict __argz,
50 size_t *__restrict __len) __THROW;
51extern error_t argz_create (char *__const __argv[], char **__restrict __argz,
52 size_t *__restrict __len) __THROW;
53
54/* Make a '\0' separated arg vector from a SEP separated list in
55 STRING, returning it in ARGZ, and the total length in LEN. If a
56 memory allocation error occurs, ENOMEM is returned, otherwise 0.
57 The result can be destroyed using free. */
58extern error_t __argz_create_sep (__const char *__restrict __string,
59 int __sep, char **__restrict __argz,
60 size_t *__restrict __len) __THROW;
61extern error_t argz_create_sep (__const char *__restrict __string,
62 int __sep, char **__restrict __argz,
63 size_t *__restrict __len) __THROW;
64
65/* Returns the number of strings in ARGZ. */
66extern size_t __argz_count (__const char *__argz, size_t __len)
67 __THROW __attribute_pure__;
68extern size_t argz_count (__const char *__argz, size_t __len)
69 __THROW __attribute_pure__;
70
71/* Puts pointers to each string in ARGZ into ARGV, which must be large enough
72 to hold them all. */
73extern void __argz_extract (__const char *__restrict __argz, size_t __len,
74 char **__restrict __argv) __THROW;
75extern void argz_extract (__const char *__restrict __argz, size_t __len,
76 char **__restrict __argv) __THROW;
77
78/* Make '\0' separated arg vector ARGZ printable by converting all the '\0's
79 except the last into the character SEP. */
80extern void __argz_stringify (char *__argz, size_t __len, int __sep) __THROW;
81extern void argz_stringify (char *__argz, size_t __len, int __sep) __THROW;
82
83/* Append BUF, of length BUF_LEN to the argz vector in ARGZ & ARGZ_LEN. */
84extern error_t __argz_append (char **__restrict __argz,
85 size_t *__restrict __argz_len,
86 __const char *__restrict __buf, size_t _buf_len)
87 __THROW;
88extern error_t argz_append (char **__restrict __argz,
89 size_t *__restrict __argz_len,
90 __const char *__restrict __buf, size_t __buf_len)
91 __THROW;
92
93/* Append STR to the argz vector in ARGZ & ARGZ_LEN. */
94extern error_t __argz_add (char **__restrict __argz,
95 size_t *__restrict __argz_len,
96 __const char *__restrict __str) __THROW;
97extern error_t argz_add (char **__restrict __argz,
98 size_t *__restrict __argz_len,
99 __const char *__restrict __str) __THROW;
100
101/* Append SEP separated list in STRING to the argz vector in ARGZ &
102 ARGZ_LEN. */
103extern error_t __argz_add_sep (char **__restrict __argz,
104 size_t *__restrict __argz_len,
105 __const char *__restrict __string, int __delim)
106 __THROW;
107extern error_t argz_add_sep (char **__restrict __argz,
108 size_t *__restrict __argz_len,
109 __const char *__restrict __string, int __delim)
110 __THROW;
111
112/* Delete ENTRY from ARGZ & ARGZ_LEN, if it appears there. */
113extern void __argz_delete (char **__restrict __argz,
114 size_t *__restrict __argz_len,
115 char *__restrict __entry) __THROW;
116extern void argz_delete (char **__restrict __argz,
117 size_t *__restrict __argz_len,
118 char *__restrict __entry) __THROW;
119
120/* Insert ENTRY into ARGZ & ARGZ_LEN before BEFORE, which should be an
121 existing entry in ARGZ; if BEFORE is NULL, ENTRY is appended to the end.
122 Since ARGZ's first entry is the same as ARGZ, argz_insert (ARGZ, ARGZ_LEN,
123 ARGZ, ENTRY) will insert ENTRY at the beginning of ARGZ. If BEFORE is not
124 in ARGZ, EINVAL is returned, else if memory can't be allocated for the new
125 ARGZ, ENOMEM is returned, else 0. */
126extern error_t __argz_insert (char **__restrict __argz,
127 size_t *__restrict __argz_len,
128 char *__restrict __before,
129 __const char *__restrict __entry) __THROW;
130extern error_t argz_insert (char **__restrict __argz,
131 size_t *__restrict __argz_len,
132 char *__restrict __before,
133 __const char *__restrict __entry) __THROW;
134
135/* Replace any occurrences of the string STR in ARGZ with WITH, reallocating
136 ARGZ as necessary. If REPLACE_COUNT is non-zero, *REPLACE_COUNT will be
137 incremented by number of replacements performed. */
138extern error_t __argz_replace (char **__restrict __argz,
139 size_t *__restrict __argz_len,
140 __const char *__restrict __str,
141 __const char *__restrict __with,
142 unsigned int *__restrict __replace_count);
143extern error_t argz_replace (char **__restrict __argz,
144 size_t *__restrict __argz_len,
145 __const char *__restrict __str,
146 __const char *__restrict __with,
147 unsigned int *__restrict __replace_count);
148
149
150/* Returns the next entry in ARGZ & ARGZ_LEN after ENTRY, or NULL if there
151 are no more. If entry is NULL, then the first entry is returned. This
152 behavior allows two convenient iteration styles:
153
154 char *entry = 0;
155 while ((entry = argz_next (argz, argz_len, entry)))
156 ...;
157
158 or
159
160 char *entry;
161 for (entry = argz; entry; entry = argz_next (argz, argz_len, entry))
162 ...;
163*/
164extern char *__argz_next (__const char *__restrict __argz, size_t __argz_len,
165 __const char *__restrict __entry) __THROW;
166extern char *argz_next (__const char *__restrict __argz, size_t __argz_len,
167 __const char *__restrict __entry) __THROW;
168
169#ifdef __USE_EXTERN_INLINES
170extern inline char *
171__argz_next (__const char *__argz, size_t __argz_len,
172 __const char *__entry) __THROW
173{
174 if (__entry)
175 {
176 if (__entry < __argz + __argz_len)
177 __entry = strchr (__entry, '\0') + 1;
178
179 return __entry >= __argz + __argz_len ? (char *) NULL : (char *) __entry;
180 }
181 else
182 return __argz_len > 0 ? (char *) __argz : 0;
183}
184extern inline char *
185argz_next (__const char *__argz, size_t __argz_len,
186 __const char *__entry) __THROW
187{
188 return __argz_next (__argz, __argz_len, __entry);
189}
190#endif /* Use extern inlines. */
191
192__END_DECLS
193
194#endif /* argz.h */
Note: See TracBrowser for help on using the repository browser.