Debian Codegraph @

lib/glob.in.h

raw
1 /* Copyright (C) 1991, 1992, 1995, 1996, 1997, 1998, 2023 Free Software
2 Foundation, Inc.
3
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public License as
6 published by the Free Software Foundation; either version 2 of the
7 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 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to the Free
16 Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
17 USA. */
18
19 #ifndef _GLOB_H
20 #define _GLOB_H 1
21
22 #include <stddef.h>
23
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27
28 /* Bits set in the FLAGS argument to `glob'. */
29 #define GLOB_ERR (1 << 0)/* Return on read errors. */
30 #define GLOB_MARK (1 << 1)/* Append a slash to each name. */
31 #define GLOB_NOSORT (1 << 2)/* Don't sort the names. */
32 #define GLOB_DOOFFS (1 << 3)/* Insert PGLOB->gl_offs NULLs. */
33 #define GLOB_NOCHECK (1 << 4)/* If nothing matches, return the pattern. */
34 #define GLOB_APPEND (1 << 5)/* Append to results of a previous call. */
35 #define GLOB_NOESCAPE (1 << 6)/* Backslashes don't quote metacharacters. */
36 #define GLOB_PERIOD (1 << 7)/* Leading `.' can be matched by metachars. */
37
38 #if (!defined _POSIX_C_SOURCE || _POSIX_C_SOURCE < 2 || defined _BSD_SOURCE \
39 || defined _GNU_SOURCE)
40 # define GLOB_MAGCHAR (1 << 8)/* Set in gl_flags if any metachars seen. */
41 # define GLOB_ALTDIRFUNC (1 << 9)/* Use gl_opendir et al functions. */
42 # define GLOB_BRACE (1 << 10)/* Expand "{a,b}" to "a" "b". */
43 # define GLOB_NOMAGIC (1 << 11)/* If no magic chars, return the pattern. */
44 # define GLOB_TILDE (1 << 12)/* Expand ~user and ~ to home directories. */
45 # define GLOB_ONLYDIR (1 << 13)/* Match only directories. */
46 # define GLOB_TILDE_CHECK (1 << 14)/* Like GLOB_TILDE but return an error
47 if the user name is not available. */
48 # define __GLOB_FLAGS (GLOB_ERR|GLOB_MARK|GLOB_NOSORT|GLOB_DOOFFS| \
49 GLOB_NOESCAPE|GLOB_NOCHECK|GLOB_APPEND| \
50 GLOB_PERIOD|GLOB_ALTDIRFUNC|GLOB_BRACE| \
51 GLOB_NOMAGIC|GLOB_TILDE|GLOB_ONLYDIR|GLOB_TILDE_CHECK)
52 #else
53 # define __GLOB_FLAGS (GLOB_ERR|GLOB_MARK|GLOB_NOSORT|GLOB_DOOFFS| \
54 GLOB_NOESCAPE|GLOB_NOCHECK|GLOB_APPEND| \
55 GLOB_PERIOD)
56 #endif
57
58 /* Error returns from `glob'. */
59 #define GLOB_NOSPACE 1 /* Ran out of memory. */
60 #define GLOB_ABORTED 2 /* Read error. */
61 #define GLOB_NOMATCH 3 /* No matches found. */
62 #define GLOB_NOSYS 4 /* Not implemented. */
63 #ifdef _GNU_SOURCE
64 /* Previous versions of this file defined GLOB_ABEND instead of
65 GLOB_ABORTED. Provide a compatibility definition here. */
66 # define GLOB_ABEND GLOB_ABORTED
67 #endif
68
69 /* Structure describing a globbing run. */
70 #if !defined _AMIGA && !defined VMS /* Buggy compiler. */
71 struct stat;
72 #endif
73 typedef struct
74 {
75 size_t gl_pathc; /* Count of paths matched by the pattern. */
76 char **gl_pathv; /* List of matched pathnames. */
77 size_t gl_offs; /* Slots to reserve in `gl_pathv'. */
78 int gl_flags; /* Set to FLAGS, maybe | GLOB_MAGCHAR. */
79
80 /* If the GLOB_ALTDIRFUNC flag is set, the following functions
81 are used instead of the normal file access functions. */
82 void (*gl_closedir) (void *);
83 struct dirent *(*gl_readdir) (void *);
84 void * (*gl_opendir) (const char *);
85 int (*gl_lstat) (const char *, struct stat *);
86 #if defined(VMS) && defined(__DECC) && !defined(_POSIX_C_SOURCE)
87 int (*gl_stat) (const char *, struct stat *, ...);
88 #else
89 int (*gl_stat) (const char *, struct stat *);
90 #endif
91 } glob_t;
92
93 #ifdef _LARGEFILE64_SOURCE
94 struct stat64;
95 typedef struct
96 {
97 size_t gl_pathc;
98 char **gl_pathv;
99 size_t gl_offs;
100 int gl_flags;
101
102 /* If the GLOB_ALTDIRFUNC flag is set, the following functions
103 are used instead of the normal file access functions. */
104 void (*gl_closedir) (void *);
105 struct dirent64 *(*gl_readdir) (void *);
106 void * (*gl_opendir) (const char *);
107 int (*gl_lstat) (const char *, struct stat64 *);
108 int (*gl_stat) (const char *, struct stat64 *);
109 } glob64_t;
110 #endif
111
112 #if _FILE_OFFSET_BITS == 64 && __GNUC__ < 2
113 # define glob glob64
114 # define globfree globfree64
115 #else
116 # ifdef _LARGEFILE64_SOURCE
117 extern int glob64 (const char *pattern, int flags,
118 int (*errfunc) (const char *, int),
119 glob64_t *pglob);
120
121 extern void globfree64 (glob64_t *pglob);
122 # endif
123 #endif
124
125 /* Do glob searching for PATTERN, placing results in PGLOB.
126 The bits defined above may be set in FLAGS.
127 If a directory cannot be opened or read and ERRFUNC is not nil,
128 it is called with the pathname that caused the error, and the
129 `errno' value from the failing call; if it returns non-zero
130 `glob' returns GLOB_ABEND; if it returns zero, the error is ignored.
131 If memory cannot be allocated for PGLOB, GLOB_NOSPACE is returned.
132 Otherwise, `glob' returns zero. */
133 #if _FILE_OFFSET_BITS != 64 || __GNUC__ < 2
134 extern int glob (const char *pattern, int flags,
135 int (*errfunc) (const char *, int),
136 glob_t *pglob);
137
138 /* Free storage allocated in PGLOB by a previous `glob' call. */
139 extern void globfree (glob_t *pglob);
140 #else
141 extern int glob (const char *pattern, int flags,
142 int (*errfunc) (const char *, int),
143 glob_t *pglob) __asm__ ("glob64");
144
145 extern void globfree (glob_t *pglob) __asm__ ("globfree64");
146 #endif
147
148
149 #ifdef _GNU_SOURCE
150 /* Return nonzero if PATTERN contains any metacharacters.
151 Metacharacters can be quoted with backslashes if QUOTE is nonzero.
152
153 This function is not part of the interface specified by POSIX.2
154 but several programs want to use it. */
155 extern int glob_pattern_p (const char *pattern, int quote);
156 #endif
157
158 #ifdef __cplusplus
159 }
160 #endif
161
162 #endif /* glob.h */