(root)/
texinfo-7.1/
gnulib/
lib/
argz.in.h
       1  /* Routines for dealing with '\0' separated arg vectors.
       2     Copyright (C) 1995-2000, 2004, 2007, 2009-2023 Free Software Foundation,
       3     Inc.
       4     This file is part of the GNU C Library.
       5  
       6     This file is free software: you can redistribute it and/or modify
       7     it under the terms of the GNU Lesser General Public License as
       8     published by the Free Software Foundation; either version 2.1 of the
       9     License, or (at your option) any later version.
      10  
      11     This file 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 Lesser General Public License for more details.
      15  
      16     You should have received a copy of the GNU Lesser General Public License
      17     along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
      18  
      19  #ifndef _ARGZ_H
      20  #define _ARGZ_H 1
      21  
      22  
      23  #define __need_error_t
      24  #include <errno.h>
      25  #include <string.h>             /* Need size_t.  */
      26  
      27  #ifndef __error_t_defined
      28  typedef int error_t;
      29  #endif
      30  
      31  
      32  
      33  /* Make a '\0' separated arg vector from a unix argv vector, returning it in
      34     ARGZ, and the total length in LEN.  If a memory allocation error occurs,
      35     ENOMEM is returned, otherwise 0.  The result can be destroyed using free.  */
      36  
      37  extern error_t argz_create (char *const /*argv*/[], char **restrict /*argz*/,
      38                              size_t *restrict /*len*/);
      39  
      40  /* Make a '\0' separated arg vector from a SEP separated list in
      41     STRING, returning it in ARGZ, and the total length in LEN.  If a
      42     memory allocation error occurs, ENOMEM is returned, otherwise 0.
      43     The result can be destroyed using free.  */
      44  
      45  extern error_t argz_create_sep (const char *restrict /*string*/,
      46                                  int /*sep*/, char **restrict /*argz*/,
      47                                  size_t *restrict /*len*/);
      48  
      49  /* Returns the number of strings in ARGZ.  */
      50  
      51  extern size_t argz_count (const char * /*argz*/, size_t /*len*/);
      52  
      53  /* Puts pointers to each string in ARGZ into ARGV, which must be large enough
      54     to hold them all.  */
      55  
      56  extern void argz_extract (const char *restrict /*argz*/, size_t /*len*/,
      57                            char **restrict /*argv*/);
      58  
      59  /* Make '\0' separated arg vector ARGZ printable by converting all the '\0's
      60     except the last into the character SEP.  */
      61  
      62  extern void argz_stringify (char * /*argz*/, size_t /*len*/, int /*sep*/);
      63  
      64  /* Append BUF, of length BUF_LEN to the argz vector in ARGZ & ARGZ_LEN.  */
      65  
      66  extern error_t argz_append (char **restrict /*argz*/,
      67                              size_t *restrict /*argz_len*/,
      68                              const char *restrict /*buf*/, size_t /*buf_len*/);
      69  
      70  /* Append STR to the argz vector in ARGZ & ARGZ_LEN.  */
      71  
      72  extern error_t argz_add (char **restrict /*argz*/,
      73                           size_t *restrict /*argz_len*/,
      74                           const char *restrict str);
      75  
      76  /* Append SEP separated list in STRING to the argz vector in ARGZ &
      77     ARGZ_LEN.  */
      78  
      79  extern error_t argz_add_sep (char **restrict /*argz*/,
      80                               size_t *restrict /*argz_len*/,
      81                               const char *restrict /*string*/, int /*delim*/);
      82  
      83  /* Delete ENTRY from ARGZ & ARGZ_LEN, if it appears there.  */
      84  
      85  extern void argz_delete (char **restrict /*argz*/,
      86                           size_t *restrict /*argz_len*/,
      87                           char *restrict /*entry*/);
      88  
      89  /* Insert ENTRY into ARGZ & ARGZ_LEN before BEFORE, which should be an
      90     existing entry in ARGZ; if BEFORE is NULL, ENTRY is appended to the end.
      91     Since ARGZ's first entry is the same as ARGZ, argz_insert (ARGZ, ARGZ_LEN,
      92     ARGZ, ENTRY) will insert ENTRY at the beginning of ARGZ.  If BEFORE is not
      93     in ARGZ, EINVAL is returned, else if memory can't be allocated for the new
      94     ARGZ, ENOMEM is returned, else 0.  */
      95  
      96  extern error_t argz_insert (char **restrict /*argz*/,
      97                              size_t *restrict /*argz_len*/,
      98                              char *restrict /*before*/,
      99                              const char *restrict /*entry*/);
     100  
     101  /* Replace any occurrences of the string STR in ARGZ with WITH, reallocating
     102     ARGZ as necessary.  If REPLACE_COUNT is non-zero, *REPLACE_COUNT will be
     103     incremented by number of replacements performed.  */
     104  
     105  extern error_t argz_replace (char **restrict /*argz*/,
     106                               size_t *restrict /*argz_len*/,
     107                               const char *restrict /*str*/,
     108                               const char *restrict /*with*/,
     109                               unsigned int *restrict /*replace_count*/);
     110  
     111  /* Returns the next entry in ARGZ & ARGZ_LEN after ENTRY, or NULL if there
     112     are no more.  If entry is NULL, then the first entry is returned.  This
     113     behavior allows two convenient iteration styles:
     114  
     115      char *entry = 0;
     116      while ((entry = argz_next (argz, argz_len, entry)))
     117        ...;
     118  
     119     or
     120  
     121      char *entry;
     122      for (entry = argz; entry; entry = argz_next (argz, argz_len, entry))
     123        ...;
     124  */
     125  
     126  extern char *argz_next (const char *restrict /*argz*/, size_t /*argz_len*/,
     127                          const char *restrict /*entry*/);
     128  
     129  
     130  #endif /* argz.h */