xref: /netbsd-src/external/gpl2/gmake/dist/glob/glob.h (revision 69606e3f5c9388e52aed8c120ad63c049ca45d8f)
1*69606e3fSchristos /* Copyright (C) 1991, 92, 95, 96, 97, 98 Free Software Foundation, Inc.
2*69606e3fSchristos 
3*69606e3fSchristos The GNU C Library is free software; you can redistribute it and/or
4*69606e3fSchristos modify it under the terms of the GNU Library General Public License as
5*69606e3fSchristos published by the Free Software Foundation; either version 2 of the
6*69606e3fSchristos License, or (at your option) any later version.
7*69606e3fSchristos 
8*69606e3fSchristos The GNU C Library is distributed in the hope that it will be useful,
9*69606e3fSchristos but WITHOUT ANY WARRANTY; without even the implied warranty of
10*69606e3fSchristos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11*69606e3fSchristos Library General Public License for more details.
12*69606e3fSchristos 
13*69606e3fSchristos You should have received a copy of the GNU Library General Public License
14*69606e3fSchristos along with this library; see the file COPYING.LIB.  If not, write to the Free
15*69606e3fSchristos Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
16*69606e3fSchristos USA.  */
17*69606e3fSchristos 
18*69606e3fSchristos #ifndef	_GLOB_H
19*69606e3fSchristos #define	_GLOB_H	1
20*69606e3fSchristos 
21*69606e3fSchristos #ifdef	__cplusplus
22*69606e3fSchristos extern "C" {
23*69606e3fSchristos #endif
24*69606e3fSchristos 
25*69606e3fSchristos #undef	__ptr_t
26*69606e3fSchristos #if defined __cplusplus || (defined __STDC__ && __STDC__) || defined WINDOWS32
27*69606e3fSchristos # if !defined __GLIBC__
28*69606e3fSchristos #  undef __P
29*69606e3fSchristos #  undef __PMT
30*69606e3fSchristos #  define __P(protos)	protos
31*69606e3fSchristos #  define __PMT(protos)	protos
32*69606e3fSchristos #  if !defined __GNUC__ || __GNUC__ < 2
33*69606e3fSchristos #   undef __const
34*69606e3fSchristos #   define __const const
35*69606e3fSchristos #  endif
36*69606e3fSchristos # endif
37*69606e3fSchristos # define __ptr_t	void *
38*69606e3fSchristos #else /* Not C++ or ANSI C.  */
39*69606e3fSchristos # undef	__P
40*69606e3fSchristos # undef __PMT
41*69606e3fSchristos # define __P(protos)	()
42*69606e3fSchristos # define __PMT(protos)	()
43*69606e3fSchristos # undef	__const
44*69606e3fSchristos # define __const
45*69606e3fSchristos # define __ptr_t	char *
46*69606e3fSchristos #endif /* C++ or ANSI C.  */
47*69606e3fSchristos 
48*69606e3fSchristos /* We need `size_t' for the following definitions.  */
49*69606e3fSchristos #ifndef __size_t
50*69606e3fSchristos # if defined __FreeBSD__
51*69606e3fSchristos #  define __size_t size_t
52*69606e3fSchristos # else
53*69606e3fSchristos #  if defined __GNUC__ && __GNUC__ >= 2
54*69606e3fSchristos typedef __SIZE_TYPE__ __size_t;
55*69606e3fSchristos #  else
56*69606e3fSchristos /* This is a guess.  */
57*69606e3fSchristos /*hb
58*69606e3fSchristos  *	Conflicts with DECCs aready defined type __size_t.
59*69606e3fSchristos  *	Defining an own type with a name beginning with '__' is no good.
60*69606e3fSchristos  *	Anyway if DECC is used and __SIZE_T is defined then __size_t is
61*69606e3fSchristos  *	already defined (and I hope it's exactly the one we need here).
62*69606e3fSchristos  */
63*69606e3fSchristos #   if !(defined __DECC && defined __SIZE_T)
64*69606e3fSchristos typedef unsigned long int __size_t;
65*69606e3fSchristos #   endif
66*69606e3fSchristos #  endif
67*69606e3fSchristos # endif
68*69606e3fSchristos #else
69*69606e3fSchristos /* The GNU CC stddef.h version defines __size_t as empty.  We need a real
70*69606e3fSchristos    definition.  */
71*69606e3fSchristos # undef __size_t
72*69606e3fSchristos # define __size_t size_t
73*69606e3fSchristos #endif
74*69606e3fSchristos 
75*69606e3fSchristos /* Bits set in the FLAGS argument to `glob'.  */
76*69606e3fSchristos #define	GLOB_ERR	(1 << 0)/* Return on read errors.  */
77*69606e3fSchristos #define	GLOB_MARK	(1 << 1)/* Append a slash to each name.  */
78*69606e3fSchristos #define	GLOB_NOSORT	(1 << 2)/* Don't sort the names.  */
79*69606e3fSchristos #define	GLOB_DOOFFS	(1 << 3)/* Insert PGLOB->gl_offs NULLs.  */
80*69606e3fSchristos #define	GLOB_NOCHECK	(1 << 4)/* If nothing matches, return the pattern.  */
81*69606e3fSchristos #define	GLOB_APPEND	(1 << 5)/* Append to results of a previous call.  */
82*69606e3fSchristos #define	GLOB_NOESCAPE	(1 << 6)/* Backslashes don't quote metacharacters.  */
83*69606e3fSchristos #define	GLOB_PERIOD	(1 << 7)/* Leading `.' can be matched by metachars.  */
84*69606e3fSchristos 
85*69606e3fSchristos #if (!defined _POSIX_C_SOURCE || _POSIX_C_SOURCE < 2 || defined _BSD_SOURCE \
86*69606e3fSchristos      || defined _GNU_SOURCE)
87*69606e3fSchristos # define GLOB_MAGCHAR	 (1 << 8)/* Set in gl_flags if any metachars seen.  */
88*69606e3fSchristos # define GLOB_ALTDIRFUNC (1 << 9)/* Use gl_opendir et al functions.  */
89*69606e3fSchristos # define GLOB_BRACE	 (1 << 10)/* Expand "{a,b}" to "a" "b".  */
90*69606e3fSchristos # define GLOB_NOMAGIC	 (1 << 11)/* If no magic chars, return the pattern.  */
91*69606e3fSchristos # define GLOB_TILDE	 (1 << 12)/* Expand ~user and ~ to home directories. */
92*69606e3fSchristos # define GLOB_ONLYDIR	 (1 << 13)/* Match only directories.  */
93*69606e3fSchristos # define GLOB_TILDE_CHECK (1 << 14)/* Like GLOB_TILDE but return an error
94*69606e3fSchristos 				      if the user name is not available.  */
95*69606e3fSchristos # define __GLOB_FLAGS	(GLOB_ERR|GLOB_MARK|GLOB_NOSORT|GLOB_DOOFFS| \
96*69606e3fSchristos 			 GLOB_NOESCAPE|GLOB_NOCHECK|GLOB_APPEND|     \
97*69606e3fSchristos 			 GLOB_PERIOD|GLOB_ALTDIRFUNC|GLOB_BRACE|     \
98*69606e3fSchristos 			 GLOB_NOMAGIC|GLOB_TILDE|GLOB_ONLYDIR|GLOB_TILDE_CHECK)
99*69606e3fSchristos #else
100*69606e3fSchristos # define __GLOB_FLAGS	(GLOB_ERR|GLOB_MARK|GLOB_NOSORT|GLOB_DOOFFS| \
101*69606e3fSchristos 			 GLOB_NOESCAPE|GLOB_NOCHECK|GLOB_APPEND|     \
102*69606e3fSchristos 			 GLOB_PERIOD)
103*69606e3fSchristos #endif
104*69606e3fSchristos 
105*69606e3fSchristos /* Error returns from `glob'.  */
106*69606e3fSchristos #define	GLOB_NOSPACE	1	/* Ran out of memory.  */
107*69606e3fSchristos #define	GLOB_ABORTED	2	/* Read error.  */
108*69606e3fSchristos #define	GLOB_NOMATCH	3	/* No matches found.  */
109*69606e3fSchristos #define GLOB_NOSYS	4	/* Not implemented.  */
110*69606e3fSchristos #ifdef _GNU_SOURCE
111*69606e3fSchristos /* Previous versions of this file defined GLOB_ABEND instead of
112*69606e3fSchristos    GLOB_ABORTED.  Provide a compatibility definition here.  */
113*69606e3fSchristos # define GLOB_ABEND GLOB_ABORTED
114*69606e3fSchristos #endif
115*69606e3fSchristos 
116*69606e3fSchristos /* Structure describing a globbing run.  */
117*69606e3fSchristos #if !defined _AMIGA && !defined VMS /* Buggy compiler.   */
118*69606e3fSchristos struct stat;
119*69606e3fSchristos #endif
120*69606e3fSchristos typedef struct
121*69606e3fSchristos   {
122*69606e3fSchristos     __size_t gl_pathc;		/* Count of paths matched by the pattern.  */
123*69606e3fSchristos     char **gl_pathv;		/* List of matched pathnames.  */
124*69606e3fSchristos     __size_t gl_offs;		/* Slots to reserve in `gl_pathv'.  */
125*69606e3fSchristos     int gl_flags;		/* Set to FLAGS, maybe | GLOB_MAGCHAR.  */
126*69606e3fSchristos 
127*69606e3fSchristos     /* If the GLOB_ALTDIRFUNC flag is set, the following functions
128*69606e3fSchristos        are used instead of the normal file access functions.  */
129*69606e3fSchristos     void (*gl_closedir) __PMT ((void *));
130*69606e3fSchristos     struct dirent *(*gl_readdir) __PMT ((void *));
131*69606e3fSchristos     __ptr_t (*gl_opendir) __PMT ((__const char *));
132*69606e3fSchristos     int (*gl_lstat) __PMT ((__const char *, struct stat *));
133*69606e3fSchristos #if defined(VMS) && defined(__DECC) && !defined(_POSIX_C_SOURCE)
134*69606e3fSchristos     int (*gl_stat) __PMT ((__const char *, struct stat *, ...));
135*69606e3fSchristos #else
136*69606e3fSchristos     int (*gl_stat) __PMT ((__const char *, struct stat *));
137*69606e3fSchristos #endif
138*69606e3fSchristos   } glob_t;
139*69606e3fSchristos 
140*69606e3fSchristos #ifdef _LARGEFILE64_SOURCE
141*69606e3fSchristos struct stat64;
142*69606e3fSchristos typedef struct
143*69606e3fSchristos   {
144*69606e3fSchristos     __size_t gl_pathc;
145*69606e3fSchristos     char **gl_pathv;
146*69606e3fSchristos     __size_t gl_offs;
147*69606e3fSchristos     int gl_flags;
148*69606e3fSchristos 
149*69606e3fSchristos     /* If the GLOB_ALTDIRFUNC flag is set, the following functions
150*69606e3fSchristos        are used instead of the normal file access functions.  */
151*69606e3fSchristos     void (*gl_closedir) __PMT ((void *));
152*69606e3fSchristos     struct dirent64 *(*gl_readdir) __PMT ((void *));
153*69606e3fSchristos     __ptr_t (*gl_opendir) __PMT ((__const char *));
154*69606e3fSchristos     int (*gl_lstat) __PMT ((__const char *, struct stat64 *));
155*69606e3fSchristos     int (*gl_stat) __PMT ((__const char *, struct stat64 *));
156*69606e3fSchristos   } glob64_t;
157*69606e3fSchristos #endif
158*69606e3fSchristos 
159*69606e3fSchristos #if _FILE_OFFSET_BITS == 64 && __GNUC__ < 2
160*69606e3fSchristos # define glob glob64
161*69606e3fSchristos # define globfree globfree64
162*69606e3fSchristos #else
163*69606e3fSchristos # ifdef _LARGEFILE64_SOURCE
164*69606e3fSchristos extern int glob64 __P ((__const char *__pattern, int __flags,
165*69606e3fSchristos 			int (*__errfunc) (__const char *, int),
166*69606e3fSchristos 			glob64_t *__pglob));
167*69606e3fSchristos 
168*69606e3fSchristos extern void globfree64 __P ((glob64_t *__pglob));
169*69606e3fSchristos # endif
170*69606e3fSchristos #endif
171*69606e3fSchristos 
172*69606e3fSchristos /* Do glob searching for PATTERN, placing results in PGLOB.
173*69606e3fSchristos    The bits defined above may be set in FLAGS.
174*69606e3fSchristos    If a directory cannot be opened or read and ERRFUNC is not nil,
175*69606e3fSchristos    it is called with the pathname that caused the error, and the
176*69606e3fSchristos    `errno' value from the failing call; if it returns non-zero
177*69606e3fSchristos    `glob' returns GLOB_ABEND; if it returns zero, the error is ignored.
178*69606e3fSchristos    If memory cannot be allocated for PGLOB, GLOB_NOSPACE is returned.
179*69606e3fSchristos    Otherwise, `glob' returns zero.  */
180*69606e3fSchristos #if _FILE_OFFSET_BITS != 64 || __GNUC__ < 2
181*69606e3fSchristos extern int glob __P ((__const char *__pattern, int __flags,
182*69606e3fSchristos 		      int (*__errfunc) (__const char *, int),
183*69606e3fSchristos 		      glob_t *__pglob));
184*69606e3fSchristos 
185*69606e3fSchristos /* Free storage allocated in PGLOB by a previous `glob' call.  */
186*69606e3fSchristos extern void globfree __P ((glob_t *__pglob));
187*69606e3fSchristos #else
188*69606e3fSchristos extern int glob __P ((__const char *__pattern, int __flags,
189*69606e3fSchristos 		      int (*__errfunc) (__const char *, int),
190*69606e3fSchristos 		      glob_t *__pglob)) __asm__ ("glob64");
191*69606e3fSchristos 
192*69606e3fSchristos extern void globfree __P ((glob_t *__pglob)) __asm__ ("globfree64");
193*69606e3fSchristos #endif
194*69606e3fSchristos 
195*69606e3fSchristos 
196*69606e3fSchristos #ifdef _GNU_SOURCE
197*69606e3fSchristos /* Return nonzero if PATTERN contains any metacharacters.
198*69606e3fSchristos    Metacharacters can be quoted with backslashes if QUOTE is nonzero.
199*69606e3fSchristos 
200*69606e3fSchristos    This function is not part of the interface specified by POSIX.2
201*69606e3fSchristos    but several programs want to use it.  */
202*69606e3fSchristos extern int glob_pattern_p __P ((__const char *__pattern, int __quote));
203*69606e3fSchristos #endif
204*69606e3fSchristos 
205*69606e3fSchristos #ifdef	__cplusplus
206*69606e3fSchristos }
207*69606e3fSchristos #endif
208*69606e3fSchristos 
209*69606e3fSchristos #endif /* glob.h  */
210