xref: /dflybsd-src/contrib/cvs-1.12/lib/glob-libc.h (revision 86d7f5d305c6adaa56ff4582ece9859d73106103)
186d7f5d3SJohn Marino /* Copyright (C) 1991,92,95-98,2000,2001,2004 Free Software Foundation, Inc.
286d7f5d3SJohn Marino    This file is part of the GNU C Library.
386d7f5d3SJohn Marino 
486d7f5d3SJohn Marino    The GNU C Library is free software; you can redistribute it and/or
586d7f5d3SJohn Marino    modify it under the terms of the GNU Lesser General Public
686d7f5d3SJohn Marino    License as published by the Free Software Foundation; either
786d7f5d3SJohn Marino    version 2.1 of the License, or (at your option) any later version.
886d7f5d3SJohn Marino 
986d7f5d3SJohn Marino    The GNU C Library is distributed in the hope that it will be useful,
1086d7f5d3SJohn Marino    but WITHOUT ANY WARRANTY; without even the implied warranty of
1186d7f5d3SJohn Marino    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
1286d7f5d3SJohn Marino    Lesser General Public License for more details.
1386d7f5d3SJohn Marino 
1486d7f5d3SJohn Marino    You should have received a copy of the GNU Lesser General Public
1586d7f5d3SJohn Marino    License along with the GNU C Library; if not, write to the Free
1686d7f5d3SJohn Marino    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
1786d7f5d3SJohn Marino    02111-1307 USA.  */
1886d7f5d3SJohn Marino 
1986d7f5d3SJohn Marino #ifndef	_GLOB_H
2086d7f5d3SJohn Marino #define	_GLOB_H	1
2186d7f5d3SJohn Marino 
2286d7f5d3SJohn Marino #ifndef __GLOB_GNULIB
2386d7f5d3SJohn Marino # include <sys/cdefs.h>
2486d7f5d3SJohn Marino #endif
2586d7f5d3SJohn Marino 
2686d7f5d3SJohn Marino __BEGIN_DECLS
2786d7f5d3SJohn Marino 
2886d7f5d3SJohn Marino /* We need `size_t' for the following definitions.  */
2986d7f5d3SJohn Marino #ifndef __size_t
3086d7f5d3SJohn Marino # if defined __GNUC__ && __GNUC__ >= 2
3186d7f5d3SJohn Marino typedef __SIZE_TYPE__ __size_t;
3286d7f5d3SJohn Marino #  ifdef __USE_XOPEN
3386d7f5d3SJohn Marino typedef __SIZE_TYPE__ size_t;
3486d7f5d3SJohn Marino #  endif
3586d7f5d3SJohn Marino # else
3686d7f5d3SJohn Marino #  include <stddef.h>
3786d7f5d3SJohn Marino #  ifndef __size_t
3886d7f5d3SJohn Marino #   define __size_t size_t
3986d7f5d3SJohn Marino #  endif
4086d7f5d3SJohn Marino # endif
4186d7f5d3SJohn Marino #else
4286d7f5d3SJohn Marino /* The GNU CC stddef.h version defines __size_t as empty.  We need a real
4386d7f5d3SJohn Marino    definition.  */
4486d7f5d3SJohn Marino # undef __size_t
4586d7f5d3SJohn Marino # define __size_t size_t
4686d7f5d3SJohn Marino #endif
4786d7f5d3SJohn Marino 
4886d7f5d3SJohn Marino /* Bits set in the FLAGS argument to `glob'.  */
4986d7f5d3SJohn Marino #define	GLOB_ERR	(1 << 0)/* Return on read errors.  */
5086d7f5d3SJohn Marino #define	GLOB_MARK	(1 << 1)/* Append a slash to each name.  */
5186d7f5d3SJohn Marino #define	GLOB_NOSORT	(1 << 2)/* Don't sort the names.  */
5286d7f5d3SJohn Marino #define	GLOB_DOOFFS	(1 << 3)/* Insert PGLOB->gl_offs NULLs.  */
5386d7f5d3SJohn Marino #define	GLOB_NOCHECK	(1 << 4)/* If nothing matches, return the pattern.  */
5486d7f5d3SJohn Marino #define	GLOB_APPEND	(1 << 5)/* Append to results of a previous call.  */
5586d7f5d3SJohn Marino #define	GLOB_NOESCAPE	(1 << 6)/* Backslashes don't quote metacharacters.  */
5686d7f5d3SJohn Marino #define	GLOB_PERIOD	(1 << 7)/* Leading `.' can be matched by metachars.  */
5786d7f5d3SJohn Marino 
5886d7f5d3SJohn Marino #if !defined __USE_POSIX2 || defined __USE_BSD || defined __USE_GNU
5986d7f5d3SJohn Marino # define GLOB_MAGCHAR	 (1 << 8)/* Set in gl_flags if any metachars seen.  */
6086d7f5d3SJohn Marino # define GLOB_ALTDIRFUNC (1 << 9)/* Use gl_opendir et al functions.  */
6186d7f5d3SJohn Marino # define GLOB_BRACE	 (1 << 10)/* Expand "{a,b}" to "a" "b".  */
6286d7f5d3SJohn Marino # define GLOB_NOMAGIC	 (1 << 11)/* If no magic chars, return the pattern.  */
6386d7f5d3SJohn Marino # define GLOB_TILDE	 (1 << 12)/* Expand ~user and ~ to home directories. */
6486d7f5d3SJohn Marino # define GLOB_ONLYDIR	 (1 << 13)/* Match only directories.  */
6586d7f5d3SJohn Marino # define GLOB_TILDE_CHECK (1 << 14)/* Like GLOB_TILDE but return an error
6686d7f5d3SJohn Marino 				      if the user name is not available.  */
6786d7f5d3SJohn Marino # define __GLOB_FLAGS	(GLOB_ERR|GLOB_MARK|GLOB_NOSORT|GLOB_DOOFFS| \
6886d7f5d3SJohn Marino 			 GLOB_NOESCAPE|GLOB_NOCHECK|GLOB_APPEND|     \
6986d7f5d3SJohn Marino 			 GLOB_PERIOD|GLOB_ALTDIRFUNC|GLOB_BRACE|     \
7086d7f5d3SJohn Marino 			 GLOB_NOMAGIC|GLOB_TILDE|GLOB_ONLYDIR|GLOB_TILDE_CHECK)
7186d7f5d3SJohn Marino #else
7286d7f5d3SJohn Marino # define __GLOB_FLAGS	(GLOB_ERR|GLOB_MARK|GLOB_NOSORT|GLOB_DOOFFS| \
7386d7f5d3SJohn Marino 			 GLOB_NOESCAPE|GLOB_NOCHECK|GLOB_APPEND|     \
7486d7f5d3SJohn Marino 			 GLOB_PERIOD)
7586d7f5d3SJohn Marino #endif
7686d7f5d3SJohn Marino 
7786d7f5d3SJohn Marino /* Error returns from `glob'.  */
7886d7f5d3SJohn Marino #define	GLOB_NOSPACE	1	/* Ran out of memory.  */
7986d7f5d3SJohn Marino #define	GLOB_ABORTED	2	/* Read error.  */
8086d7f5d3SJohn Marino #define	GLOB_NOMATCH	3	/* No matches found.  */
8186d7f5d3SJohn Marino #define GLOB_NOSYS	4	/* Not implemented.  */
8286d7f5d3SJohn Marino #ifdef __USE_GNU
8386d7f5d3SJohn Marino /* Previous versions of this file defined GLOB_ABEND instead of
8486d7f5d3SJohn Marino    GLOB_ABORTED.  Provide a compatibility definition here.  */
8586d7f5d3SJohn Marino # define GLOB_ABEND GLOB_ABORTED
8686d7f5d3SJohn Marino #endif
8786d7f5d3SJohn Marino 
8886d7f5d3SJohn Marino /* Structure describing a globbing run.  */
8986d7f5d3SJohn Marino #ifdef __USE_GNU
9086d7f5d3SJohn Marino struct stat;
9186d7f5d3SJohn Marino #endif
9286d7f5d3SJohn Marino typedef struct
9386d7f5d3SJohn Marino   {
9486d7f5d3SJohn Marino     __size_t gl_pathc;		/* Count of paths matched by the pattern.  */
9586d7f5d3SJohn Marino     char **gl_pathv;		/* List of matched pathnames.  */
9686d7f5d3SJohn Marino     __size_t gl_offs;		/* Slots to reserve in `gl_pathv'.  */
9786d7f5d3SJohn Marino     int gl_flags;		/* Set to FLAGS, maybe | GLOB_MAGCHAR.  */
9886d7f5d3SJohn Marino 
9986d7f5d3SJohn Marino     /* If the GLOB_ALTDIRFUNC flag is set, the following functions
10086d7f5d3SJohn Marino        are used instead of the normal file access functions.  */
10186d7f5d3SJohn Marino     void (*gl_closedir) (void *);
10286d7f5d3SJohn Marino #ifdef __USE_GNU
10386d7f5d3SJohn Marino     struct dirent *(*gl_readdir) (void *);
10486d7f5d3SJohn Marino #else
10586d7f5d3SJohn Marino     void *(*gl_readdir) (void *);
10686d7f5d3SJohn Marino #endif
10786d7f5d3SJohn Marino     void *(*gl_opendir) (__const char *);
10886d7f5d3SJohn Marino #ifdef __USE_GNU
10986d7f5d3SJohn Marino     int (*gl_lstat) (__const char *__restrict, struct stat *__restrict);
11086d7f5d3SJohn Marino     int (*gl_stat) (__const char *__restrict, struct stat *__restrict);
11186d7f5d3SJohn Marino #else
11286d7f5d3SJohn Marino     int (*gl_lstat) (__const char *__restrict, void *__restrict);
11386d7f5d3SJohn Marino     int (*gl_stat) (__const char *__restrict, void *__restrict);
11486d7f5d3SJohn Marino #endif
11586d7f5d3SJohn Marino   } glob_t;
11686d7f5d3SJohn Marino 
11786d7f5d3SJohn Marino #if defined __USE_LARGEFILE64 && !defined __GLOB_GNULIB
11886d7f5d3SJohn Marino # ifdef __USE_GNU
11986d7f5d3SJohn Marino struct stat64;
12086d7f5d3SJohn Marino # endif
12186d7f5d3SJohn Marino typedef struct
12286d7f5d3SJohn Marino   {
12386d7f5d3SJohn Marino     __size_t gl_pathc;
12486d7f5d3SJohn Marino     char **gl_pathv;
12586d7f5d3SJohn Marino     __size_t gl_offs;
12686d7f5d3SJohn Marino     int gl_flags;
12786d7f5d3SJohn Marino 
12886d7f5d3SJohn Marino     /* If the GLOB_ALTDIRFUNC flag is set, the following functions
12986d7f5d3SJohn Marino        are used instead of the normal file access functions.  */
13086d7f5d3SJohn Marino     void (*gl_closedir) (void *);
13186d7f5d3SJohn Marino # ifdef __USE_GNU
13286d7f5d3SJohn Marino     struct dirent64 *(*gl_readdir) (void *);
13386d7f5d3SJohn Marino # else
13486d7f5d3SJohn Marino     void *(*gl_readdir) (void *);
13586d7f5d3SJohn Marino # endif
13686d7f5d3SJohn Marino     void *(*gl_opendir) (__const char *);
13786d7f5d3SJohn Marino # ifdef __USE_GNU
13886d7f5d3SJohn Marino     int (*gl_lstat) (__const char *__restrict, struct stat64 *__restrict);
13986d7f5d3SJohn Marino     int (*gl_stat) (__const char *__restrict, struct stat64 *__restrict);
14086d7f5d3SJohn Marino # else
14186d7f5d3SJohn Marino     int (*gl_lstat) (__const char *__restrict, void *__restrict);
14286d7f5d3SJohn Marino     int (*gl_stat) (__const char *__restrict, void *__restrict);
14386d7f5d3SJohn Marino # endif
14486d7f5d3SJohn Marino   } glob64_t;
14586d7f5d3SJohn Marino #endif
14686d7f5d3SJohn Marino 
14786d7f5d3SJohn Marino #if __USE_FILE_OFFSET64 && __GNUC__ < 2 && !defined __GLOB_GNULIB
14886d7f5d3SJohn Marino # define glob glob64
14986d7f5d3SJohn Marino # define globfree globfree64
15086d7f5d3SJohn Marino #endif
15186d7f5d3SJohn Marino 
15286d7f5d3SJohn Marino /* Do glob searching for PATTERN, placing results in PGLOB.
15386d7f5d3SJohn Marino    The bits defined above may be set in FLAGS.
15486d7f5d3SJohn Marino    If a directory cannot be opened or read and ERRFUNC is not nil,
15586d7f5d3SJohn Marino    it is called with the pathname that caused the error, and the
15686d7f5d3SJohn Marino    `errno' value from the failing call; if it returns non-zero
15786d7f5d3SJohn Marino    `glob' returns GLOB_ABEND; if it returns zero, the error is ignored.
15886d7f5d3SJohn Marino    If memory cannot be allocated for PGLOB, GLOB_NOSPACE is returned.
15986d7f5d3SJohn Marino    Otherwise, `glob' returns zero.  */
16086d7f5d3SJohn Marino #if !defined __USE_FILE_OFFSET64 || __GNUC__ < 2 || defined __GLOB_GNULIB
16186d7f5d3SJohn Marino extern int glob (__const char *__restrict __pattern, int __flags,
16286d7f5d3SJohn Marino 		 int (*__errfunc) (__const char *, int),
16386d7f5d3SJohn Marino 		 glob_t *__restrict __pglob) __THROW;
16486d7f5d3SJohn Marino 
16586d7f5d3SJohn Marino /* Free storage allocated in PGLOB by a previous `glob' call.  */
16686d7f5d3SJohn Marino extern void globfree (glob_t *__pglob) __THROW;
16786d7f5d3SJohn Marino #else
16886d7f5d3SJohn Marino extern int __REDIRECT_NTH (glob, (__const char *__restrict __pattern,
16986d7f5d3SJohn Marino 				  int __flags,
17086d7f5d3SJohn Marino 				  int (*__errfunc) (__const char *, int),
17186d7f5d3SJohn Marino 				  glob_t *__restrict __pglob), glob64);
17286d7f5d3SJohn Marino 
17386d7f5d3SJohn Marino extern void __REDIRECT_NTH (globfree, (glob_t *__pglob), globfree64);
17486d7f5d3SJohn Marino #endif
17586d7f5d3SJohn Marino 
17686d7f5d3SJohn Marino #if defined __USE_LARGEFILE64 && !defined __GLOB_GNULIB
17786d7f5d3SJohn Marino extern int glob64 (__const char *__restrict __pattern, int __flags,
17886d7f5d3SJohn Marino 		   int (*__errfunc) (__const char *, int),
17986d7f5d3SJohn Marino 		   glob64_t *__restrict __pglob) __THROW;
18086d7f5d3SJohn Marino 
18186d7f5d3SJohn Marino extern void globfree64 (glob64_t *__pglob) __THROW;
18286d7f5d3SJohn Marino #endif
18386d7f5d3SJohn Marino 
18486d7f5d3SJohn Marino 
18586d7f5d3SJohn Marino #ifdef __USE_GNU
18686d7f5d3SJohn Marino /* Return nonzero if PATTERN contains any metacharacters.
18786d7f5d3SJohn Marino    Metacharacters can be quoted with backslashes if QUOTE is nonzero.
18886d7f5d3SJohn Marino 
18986d7f5d3SJohn Marino    This function is not part of the interface specified by POSIX.2
19086d7f5d3SJohn Marino    but several programs want to use it.  */
19186d7f5d3SJohn Marino extern int glob_pattern_p (__const char *__pattern, int __quote) __THROW;
19286d7f5d3SJohn Marino #endif
19386d7f5d3SJohn Marino 
19486d7f5d3SJohn Marino __END_DECLS
19586d7f5d3SJohn Marino 
19686d7f5d3SJohn Marino #endif /* glob.h  */
197