Updated from libc
[make.git] / glob / glob.h
blob6eea06298caf9fa55103c77dc4baa80bc6bc695d
1 /* Copyright (C) 1991, 1992, 1995 Free Software Foundation, Inc.
3 This library is free software; you can redistribute it and/or
4 modify it under the terms of the GNU Library General Public License as
5 published by the Free Software Foundation; either version 2 of the
6 License, or (at your option) any later version.
8 This library is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 Library General Public License for more details.
13 You should have received a copy of the GNU Library General Public
14 License along with this library; see the file COPYING.LIB. If
15 not, write to the Free Software Foundation, Inc., 675 Mass Ave,
16 Cambridge, MA 02139, USA. */
18 #ifndef _GLOB_H
20 #define _GLOB_H 1
22 #ifdef __cplusplus
23 extern "C"
25 #endif
27 #undef __ptr_t
28 #if defined (__cplusplus) || (defined (__STDC__) && __STDC__)
29 #undef __P
30 #define __P(protos) protos
31 #define __ptr_t void *
32 #else /* Not C++ or ANSI C. */
33 #undef __P
34 #define __P(protos) ()
35 #undef const
36 #define const
37 #define __ptr_t char *
38 #endif /* C++ or ANSI C. */
40 /* Bits set in the FLAGS argument to `glob'. */
41 #define GLOB_ERR (1 << 0)/* Return on read errors. */
42 #define GLOB_MARK (1 << 1)/* Append a slash to each name. */
43 #define GLOB_NOSORT (1 << 2)/* Don't sort the names. */
44 #define GLOB_DOOFFS (1 << 3)/* Insert PGLOB->gl_offs NULLs. */
45 #define GLOB_NOCHECK (1 << 4)/* If nothing matches, return the pattern. */
46 #define GLOB_APPEND (1 << 5)/* Append to results of a previous call. */
47 #define GLOB_NOESCAPE (1 << 6)/* Backslashes don't quote metacharacters. */
48 #define GLOB_PERIOD (1 << 7)/* Leading `.' can be matched by metachars. */
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)
54 #if !defined (_POSIX_C_SOURCE) || _POSIX_C_SOURCE < 2 || defined (_BSD_SOURCE)
55 #define GLOB_MAGCHAR (1 << 8)/* Set in gl_flags if any metachars seen. */
56 #define GLOB_ALTDIRFUNC (1 << 9)/* Use gl_opendir et al functions. */
57 #define GLOB_BRACE (1 << 10)/* Expand "{a,b}" to "a" "b". */
58 #define GLOB_NOMAGIC (1 << 11)/* If no magic chars, return the pattern. */
59 #define GLOB_TILDE (1 <<12)/* Expand ~user and ~ to home directories. */
60 #endif
62 /* Error returns from `glob'. */
63 #define GLOB_NOSPACE 1 /* Ran out of memory. */
64 #define GLOB_ABEND 2 /* Read error. */
65 #define GLOB_NOMATCH 3 /* No matches found. */
67 /* Structure describing a globbing run. */
68 struct stat;
69 typedef struct
71 int gl_pathc; /* Count of paths matched by the pattern. */
72 char **gl_pathv; /* List of matched pathnames. */
73 int gl_offs; /* Slots to reserve in `gl_pathv'. */
74 int gl_flags; /* Set to FLAGS, maybe | GLOB_MAGCHAR. */
76 /* If the GLOB_ALTDIRFUNC flag is set, the following functions
77 are used instead of the normal file access functions. */
78 void (*gl_closedir) __P ((void *));
79 struct dirent *(*gl_readdir) __P ((void *));
80 __ptr_t (*gl_opendir) __P ((const char *));
81 int (*gl_lstat) __P ((const char *, struct stat *));
82 int (*gl_stat) __P ((const char *, struct stat *));
83 } glob_t;
85 /* Do glob searching for PATTERN, placing results in PGLOB.
86 The bits defined above may be set in FLAGS.
87 If a directory cannot be opened or read and ERRFUNC is not nil,
88 it is called with the pathname that caused the error, and the
89 `errno' value from the failing call; if it returns non-zero
90 `glob' returns GLOB_ABEND; if it returns zero, the error is ignored.
91 If memory cannot be allocated for PGLOB, GLOB_NOSPACE is returned.
92 Otherwise, `glob' returns zero. */
93 extern int glob __P ((const char *__pattern, int __flags,
94 int (*__errfunc) __P ((const char *, int)),
95 glob_t *__pglob));
97 /* Free storage allocated in PGLOB by a previous `glob' call. */
98 extern void globfree __P ((glob_t *__pglob));
101 #if !defined (_POSIX_C_SOURCE) || _POSIX_C_SOURCE < 2 || defined (_GNU_SOURCE)
102 /* If they are not NULL, `glob' uses these functions to read directories. */
103 extern __ptr_t (*__glob_opendir_hook) __P ((const char *__directory));
104 extern const char *(*__glob_readdir_hook) __P ((__ptr_t __stream));
105 extern void (*__glob_closedir_hook) __P ((__ptr_t __stream));
106 #endif
108 #ifdef __cplusplus
110 #endif
112 #endif /* glob.h */