1/* Copyright (C) 1991-2022 Free Software Foundation, Inc.
2   This file is part of the GNU C Library.
3
4   The GNU C Library is free software; you can redistribute it and/or
5   modify it under the terms of the GNU Lesser General Public
6   License as published by the Free Software Foundation; either
7   version 2.1 of the License, or (at your option) any later version.
8
9   The GNU C Library is distributed in the hope that it will be useful,
10   but WITHOUT ANY WARRANTY; without even the implied warranty of
11   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12   Lesser General Public License for more details.
13
14   You should have received a copy of the GNU Lesser General Public
15   License along with the GNU C Library; if not, see
16   <https://www.gnu.org/licenses/>.  */
17
18#ifndef _GLOB_H
19#define _GLOB_H 1
20
21#ifndef __GLOB_GNULIB
22# include <sys/cdefs.h>
23#endif
24
25__BEGIN_DECLS
26
27#define __need_size_t
28#include <stddef.h>
29
30/* Bits set in the FLAGS argument to 'glob'.  */
31#define GLOB_ERR        (1 << 0)/* Return on read errors.  */
32#define GLOB_MARK       (1 << 1)/* Append a slash to each name.  */
33#define GLOB_NOSORT     (1 << 2)/* Don't sort the names.  */
34#define GLOB_DOOFFS     (1 << 3)/* Insert PGLOB->gl_offs NULLs.  */
35#define GLOB_NOCHECK    (1 << 4)/* If nothing matches, return the pattern.  */
36#define GLOB_APPEND     (1 << 5)/* Append to results of a previous call.  */
37#define GLOB_NOESCAPE   (1 << 6)/* Backslashes don't quote metacharacters.  */
38#define GLOB_PERIOD     (1 << 7)/* Leading '.' can be matched by metachars.  */
39
40#if !defined __USE_POSIX2 || defined __USE_MISC
41# define GLOB_MAGCHAR    (1 << 8)/* Set in gl_flags if any metachars seen.  */
42# define GLOB_ALTDIRFUNC (1 << 9)/* Use gl_opendir et al functions.  */
43# define GLOB_BRACE      (1 << 10)/* Expand "{a,b}" to "a" "b".  */
44# define GLOB_NOMAGIC    (1 << 11)/* If no magic chars, return the pattern.  */
45# define GLOB_TILDE      (1 << 12)/* Expand ~user and ~ to home directories. */
46# define GLOB_ONLYDIR    (1 << 13)/* Match only directories.  */
47# define GLOB_TILDE_CHECK (1 << 14)/* Like GLOB_TILDE but return an error
48                                      if the user name is not available.  */
49# define __GLOB_FLAGS   (GLOB_ERR|GLOB_MARK|GLOB_NOSORT|GLOB_DOOFFS  \
50                         |GLOB_NOESCAPE|GLOB_NOCHECK|GLOB_APPEND     \
51                         |GLOB_PERIOD|GLOB_ALTDIRFUNC|GLOB_BRACE     \
52                         |GLOB_NOMAGIC|GLOB_TILDE|GLOB_ONLYDIR|GLOB_TILDE_CHECK)
53#else
54# define __GLOB_FLAGS   (GLOB_ERR|GLOB_MARK|GLOB_NOSORT|GLOB_DOOFFS  \
55                         |GLOB_NOESCAPE|GLOB_NOCHECK|GLOB_APPEND     \
56                         |GLOB_PERIOD)
57#endif
58
59/* Error returns from 'glob'.  */
60#define GLOB_NOSPACE    1       /* Ran out of memory.  */
61#define GLOB_ABORTED    2       /* Read error.  */
62#define GLOB_NOMATCH    3       /* No matches found.  */
63#define GLOB_NOSYS      4       /* Not implemented.  */
64#ifdef __USE_GNU
65/* Previous versions of this file defined GLOB_ABEND instead of
66   GLOB_ABORTED.  Provide a compatibility definition here.  */
67# define GLOB_ABEND GLOB_ABORTED
68#endif
69
70/* Structure describing a globbing run.  */
71#ifdef __USE_GNU
72struct stat;
73#endif
74typedef struct
75  {
76    size_t gl_pathc;          /* Count of paths matched by the pattern.  */
77    char **gl_pathv;            /* List of matched pathnames.  */
78    size_t gl_offs;           /* Slots to reserve in 'gl_pathv'.  */
79    int gl_flags;               /* Set to FLAGS, maybe | GLOB_MAGCHAR.  */
80
81    /* If the GLOB_ALTDIRFUNC flag is set, the following functions
82       are used instead of the normal file access functions.  */
83    void (*gl_closedir) (void *);
84#ifdef __USE_GNU
85    struct dirent *(*gl_readdir) (void *);
86#else
87    void *(*gl_readdir) (void *);
88#endif
89    void *(*gl_opendir) (const char *);
90#ifdef __USE_GNU
91    int (*gl_lstat) (const char *__restrict, struct stat *__restrict);
92    int (*gl_stat) (const char *__restrict, struct stat *__restrict);
93#else
94    int (*gl_lstat) (const char *__restrict, void *__restrict);
95    int (*gl_stat) (const char *__restrict, void *__restrict);
96#endif
97  } glob_t;
98
99#ifdef __USE_LARGEFILE64
100# ifdef __USE_GNU
101struct stat64;
102# endif
103typedef struct
104  {
105    size_t gl_pathc;
106    char **gl_pathv;
107    size_t gl_offs;
108    int gl_flags;
109
110    /* If the GLOB_ALTDIRFUNC flag is set, the following functions
111       are used instead of the normal file access functions.  */
112    void (*gl_closedir) (void *);
113# ifdef __USE_GNU
114    struct dirent64 *(*gl_readdir) (void *);
115# else
116    void *(*gl_readdir) (void *);
117# endif
118    void *(*gl_opendir) (const char *);
119# ifdef __USE_GNU
120    int (*gl_lstat) (const char *__restrict, struct stat64 *__restrict);
121    int (*gl_stat) (const char *__restrict, struct stat64 *__restrict);
122# else
123    int (*gl_lstat) (const char *__restrict, void *__restrict);
124    int (*gl_stat) (const char *__restrict, void *__restrict);
125# endif
126  } glob64_t;
127#endif
128
129/* Do glob searching for PATTERN, placing results in PGLOB.
130   The bits defined above may be set in FLAGS.
131   If a directory cannot be opened or read and ERRFUNC is not nil,
132   it is called with the pathname that caused the error, and the
133   'errno' value from the failing call; if it returns non-zero
134   'glob' returns GLOB_ABEND; if it returns zero, the error is ignored.
135   If memory cannot be allocated for PGLOB, GLOB_NOSPACE is returned.
136   Otherwise, 'glob' returns zero.  */
137#if !defined __USE_FILE_OFFSET64 || defined __GLOB_GNULIB
138extern int glob (const char *__restrict __pattern, int __flags,
139                 int (*__errfunc) (const char *, int),
140                 glob_t *__restrict __pglob) __THROWNL;
141
142/* Free storage allocated in PGLOB by a previous 'glob' call.  */
143extern void globfree (glob_t *__pglob) __THROW;
144#else
145# ifdef __USE_TIME_BITS64
146extern int __REDIRECT_NTHNL (glob, (const char *__restrict __pattern,
147                                   int __flags,
148                                   int (*__errfunc) (const char *, int),
149                                   glob_t *__restrict __pglob),
150                            __glob64_time64);
151
152extern void __REDIRECT_NTH (globfree, (glob_t *__pglob),
153                           __globfree64_time64);
154# else
155extern int __REDIRECT_NTHNL (glob, (const char *__restrict __pattern,
156                                    int __flags,
157                                    int (*__errfunc) (const char *, int),
158                                    glob_t *__restrict __pglob), glob64);
159
160extern void __REDIRECT_NTH (globfree, (glob_t *__pglob), globfree64);
161# endif
162#endif
163
164#ifdef __USE_LARGEFILE64
165# ifdef __USE_TIME_BITS64
166extern int __REDIRECT_NTHNL (glob64, (const char *__restrict __pattern,
167                                     int __flags,
168                                     int (*__errfunc) (const char *, int),
169                                     glob64_t *__restrict __pglob),
170                            __glob64_time64);
171
172extern void __REDIRECT_NTH (globfree64, (glob64_t *__pglob),
173                           __globfree64_time64);
174# else
175extern int glob64 (const char *__restrict __pattern, int __flags,
176                   int (*__errfunc) (const char *, int),
177                   glob64_t *__restrict __pglob) __THROWNL;
178
179extern void globfree64 (glob64_t *__pglob) __THROW;
180# endif
181#endif
182
183
184#ifdef __USE_GNU
185/* Return nonzero if PATTERN contains any metacharacters.
186   Metacharacters can be quoted with backslashes if QUOTE is nonzero.
187
188   This function is not part of the interface specified by POSIX.2
189   but several programs want to use it.  */
190extern int glob_pattern_p (const char *__pattern, int __quote) __THROW;
191#endif
192
193__END_DECLS
194
195#endif /* glob.h  */
196