|
Packit |
6c4009 |
/* Routines for dealing with '\0' separated arg vectors.
|
|
Packit |
6c4009 |
Copyright (C) 1995-2018 Free Software Foundation, Inc.
|
|
Packit |
6c4009 |
This file is part of the GNU C Library.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
The GNU C Library is free software; you can redistribute it and/or
|
|
Packit |
6c4009 |
modify it under the terms of the GNU Lesser General Public
|
|
Packit |
6c4009 |
License as published by the Free Software Foundation; either
|
|
Packit |
6c4009 |
version 2.1 of the License, or (at your option) any later version.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
The GNU C Library is distributed in the hope that it will be useful,
|
|
Packit |
6c4009 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
6c4009 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit |
6c4009 |
Lesser General Public License for more details.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
You should have received a copy of the GNU Lesser General Public
|
|
Packit |
6c4009 |
License along with the GNU C Library; if not, see
|
|
Packit |
6c4009 |
<http://www.gnu.org/licenses/>. */
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#ifndef _ARGZ_H
|
|
Packit |
6c4009 |
#define _ARGZ_H 1
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#include <features.h>
|
|
Packit |
6c4009 |
#include <errno.h>
|
|
Packit |
6c4009 |
#include <string.h> /* Need size_t, and strchr is called below. */
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
__BEGIN_DECLS
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* error_t may or may not be available from errno.h, depending on the
|
|
Packit |
6c4009 |
operating system. */
|
|
Packit |
6c4009 |
#ifndef __error_t_defined
|
|
Packit |
6c4009 |
# define __error_t_defined 1
|
|
Packit |
6c4009 |
typedef int error_t;
|
|
Packit |
6c4009 |
#endif
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Make a '\0' separated arg vector from a unix argv vector, returning it in
|
|
Packit |
6c4009 |
ARGZ, and the total length in LEN. If a memory allocation error occurs,
|
|
Packit |
6c4009 |
ENOMEM is returned, otherwise 0. The result can be destroyed using free. */
|
|
Packit |
6c4009 |
extern error_t __argz_create (char *const __argv[], char **__restrict __argz,
|
|
Packit |
6c4009 |
size_t *__restrict __len) __THROW;
|
|
Packit |
6c4009 |
extern error_t argz_create (char *const __argv[], char **__restrict __argz,
|
|
Packit |
6c4009 |
size_t *__restrict __len) __THROW;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Make a '\0' separated arg vector from a SEP separated list in
|
|
Packit |
6c4009 |
STRING, returning it in ARGZ, and the total length in LEN. If a
|
|
Packit |
6c4009 |
memory allocation error occurs, ENOMEM is returned, otherwise 0.
|
|
Packit |
6c4009 |
The result can be destroyed using free. */
|
|
Packit |
6c4009 |
extern error_t argz_create_sep (const char *__restrict __string,
|
|
Packit |
6c4009 |
int __sep, char **__restrict __argz,
|
|
Packit |
6c4009 |
size_t *__restrict __len) __THROW;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Returns the number of strings in ARGZ. */
|
|
Packit |
6c4009 |
extern size_t __argz_count (const char *__argz, size_t __len)
|
|
Packit |
6c4009 |
__THROW __attribute_pure__;
|
|
Packit |
6c4009 |
extern size_t argz_count (const char *__argz, size_t __len)
|
|
Packit |
6c4009 |
__THROW __attribute_pure__;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Puts pointers to each string in ARGZ into ARGV, which must be large enough
|
|
Packit |
6c4009 |
to hold them all. */
|
|
Packit |
6c4009 |
extern void __argz_extract (const char *__restrict __argz, size_t __len,
|
|
Packit |
6c4009 |
char **__restrict __argv) __THROW;
|
|
Packit |
6c4009 |
extern void argz_extract (const char *__restrict __argz, size_t __len,
|
|
Packit |
6c4009 |
char **__restrict __argv) __THROW;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Make '\0' separated arg vector ARGZ printable by converting all the '\0's
|
|
Packit |
6c4009 |
except the last into the character SEP. */
|
|
Packit |
6c4009 |
extern void __argz_stringify (char *__argz, size_t __len, int __sep) __THROW;
|
|
Packit |
6c4009 |
extern void argz_stringify (char *__argz, size_t __len, int __sep) __THROW;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Append BUF, of length BUF_LEN to the argz vector in ARGZ & ARGZ_LEN. */
|
|
Packit |
6c4009 |
extern error_t argz_append (char **__restrict __argz,
|
|
Packit |
6c4009 |
size_t *__restrict __argz_len,
|
|
Packit |
6c4009 |
const char *__restrict __buf, size_t __buf_len)
|
|
Packit |
6c4009 |
__THROW;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Append STR to the argz vector in ARGZ & ARGZ_LEN. */
|
|
Packit |
6c4009 |
extern error_t argz_add (char **__restrict __argz,
|
|
Packit |
6c4009 |
size_t *__restrict __argz_len,
|
|
Packit |
6c4009 |
const char *__restrict __str) __THROW;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Append SEP separated list in STRING to the argz vector in ARGZ &
|
|
Packit |
6c4009 |
ARGZ_LEN. */
|
|
Packit |
6c4009 |
extern error_t argz_add_sep (char **__restrict __argz,
|
|
Packit |
6c4009 |
size_t *__restrict __argz_len,
|
|
Packit |
6c4009 |
const char *__restrict __string, int __delim)
|
|
Packit |
6c4009 |
__THROW;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Delete ENTRY from ARGZ & ARGZ_LEN, if it appears there. */
|
|
Packit |
6c4009 |
extern void argz_delete (char **__restrict __argz,
|
|
Packit |
6c4009 |
size_t *__restrict __argz_len,
|
|
Packit |
6c4009 |
char *__restrict __entry) __THROW;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Insert ENTRY into ARGZ & ARGZ_LEN before BEFORE, which should be an
|
|
Packit |
6c4009 |
existing entry in ARGZ; if BEFORE is NULL, ENTRY is appended to the end.
|
|
Packit |
6c4009 |
Since ARGZ's first entry is the same as ARGZ, argz_insert (ARGZ, ARGZ_LEN,
|
|
Packit |
6c4009 |
ARGZ, ENTRY) will insert ENTRY at the beginning of ARGZ. If BEFORE is not
|
|
Packit |
6c4009 |
in ARGZ, EINVAL is returned, else if memory can't be allocated for the new
|
|
Packit |
6c4009 |
ARGZ, ENOMEM is returned, else 0. */
|
|
Packit |
6c4009 |
extern error_t argz_insert (char **__restrict __argz,
|
|
Packit |
6c4009 |
size_t *__restrict __argz_len,
|
|
Packit |
6c4009 |
char *__restrict __before,
|
|
Packit |
6c4009 |
const char *__restrict __entry) __THROW;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Replace any occurrences of the string STR in ARGZ with WITH, reallocating
|
|
Packit |
6c4009 |
ARGZ as necessary. If REPLACE_COUNT is non-zero, *REPLACE_COUNT will be
|
|
Packit |
6c4009 |
incremented by number of replacements performed. */
|
|
Packit |
6c4009 |
extern error_t argz_replace (char **__restrict __argz,
|
|
Packit |
6c4009 |
size_t *__restrict __argz_len,
|
|
Packit |
6c4009 |
const char *__restrict __str,
|
|
Packit |
6c4009 |
const char *__restrict __with,
|
|
Packit |
6c4009 |
unsigned int *__restrict __replace_count);
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Returns the next entry in ARGZ & ARGZ_LEN after ENTRY, or NULL if there
|
|
Packit |
6c4009 |
are no more. If entry is NULL, then the first entry is returned. This
|
|
Packit |
6c4009 |
behavior allows two convenient iteration styles:
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
char *entry = 0;
|
|
Packit |
6c4009 |
while ((entry = argz_next (argz, argz_len, entry)))
|
|
Packit |
6c4009 |
...;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
or
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
char *entry;
|
|
Packit |
6c4009 |
for (entry = argz; entry; entry = argz_next (argz, argz_len, entry))
|
|
Packit |
6c4009 |
...;
|
|
Packit |
6c4009 |
*/
|
|
Packit |
6c4009 |
extern char *__argz_next (const char *__restrict __argz, size_t __argz_len,
|
|
Packit |
6c4009 |
const char *__restrict __entry) __THROW;
|
|
Packit |
6c4009 |
extern char *argz_next (const char *__restrict __argz, size_t __argz_len,
|
|
Packit |
6c4009 |
const char *__restrict __entry) __THROW;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#ifdef __USE_EXTERN_INLINES
|
|
Packit |
6c4009 |
__extern_inline char *
|
|
Packit |
6c4009 |
__NTH (__argz_next (const char *__argz, size_t __argz_len,
|
|
Packit |
6c4009 |
const char *__entry))
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
if (__entry)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
if (__entry < __argz + __argz_len)
|
|
Packit |
6c4009 |
__entry = strchr (__entry, '\0') + 1;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
return __entry >= __argz + __argz_len ? (char *) NULL : (char *) __entry;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
else
|
|
Packit |
6c4009 |
return __argz_len > 0 ? (char *) __argz : 0;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
__extern_inline char *
|
|
Packit |
6c4009 |
__NTH (argz_next (const char *__argz, size_t __argz_len,
|
|
Packit |
6c4009 |
const char *__entry))
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
return __argz_next (__argz, __argz_len, __entry);
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
#endif /* Use extern inlines. */
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
__END_DECLS
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#endif /* argz.h */
|