1 /**
2 * @file glob.h
3 * Copyright (C) 2012 MinGW.org project
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice, this permission notice, and the following
13 * disclaimer shall be included in all copies or substantial portions of
14 * the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OF OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 */
24 /* ---------------------------------------------------------------------------
25 *
26 * Header file supporting a MinGW implementation of an (approximately)
27 * POSIX conforming glob() and globfree() API.
28 *
29 * Written by Keith Marshall <keithmarshall@users.sourceforge.net>
30 * Copyright (C) 2011, 2012, MinGW Project.
31 *
32 * ---------------------------------------------------------------------------
33 */
34 #ifndef _GLOB_H
35 #define _GLOB_H 1
36 #include <_mingw.h>
37 #pragma GCC system_header
38
39 #ifndef RC_INVOKED
40 /* POSIX requires glob.h to define the size_t type; we need to
41 * get this from GCC, just as sys/types.h does.
42 */
43 #define __need_size_t
44 #include <stddef.h>
45
46 typedef
47 struct glob_t
48 { /* The structure, in which glob() returns the list of file system
49 * entities which it has matched.
50 */
51 void * gl_magic; /* reserved field; pointer to a glob signature */
52 size_t gl_pathc; /* counter for paths matched */
53 char ** gl_pathv; /* list of matching path names */
54 size_t gl_offs; /* number of initial unused slots in gl_pathv */
55 } glob_t;
56
57 /* A macro to facilitate definition of the flags which are used to
58 * control the operation of glob().
59 */
60 #define __GLOB_FLAG__(NAME) (1 << __GLOB_##NAME##_OFFSET)
61 enum {
62 /* Identify the zero-based offset values which are used to specify
63 * the individual bit positions for each __GLOB_FLAG; the initial
64 * list specifies the standard set of flags required by POSIX.
65 */
66 __GLOB_APPEND_OFFSET = 0,
67 __GLOB_DOOFFS_OFFSET,
68 __GLOB_ERR_OFFSET,
69 __GLOB_MARK_OFFSET,
70 __GLOB_NOCHECK_OFFSET,
71 __GLOB_NOESCAPE_OFFSET,
72 __GLOB_NOSORT_OFFSET,
73 /*
74 * GNU's implementation of glob() supports a supplementary set of
75 * options, none of which are required by POSIX. We include these
76 * for reference, and to reserve the flag identities for a possible
77 * future implementation; the current MinGW implementation does not
78 * support them.
79 */
80 __GLOB_TILDE_OFFSET,
81 __GLOB_TILDE_CHECK_OFFSET,
82 __GLOB_PERIOD_OFFSET,
83 __GLOB_BRACE_OFFSET,
84 __GLOB_ONLYDIR_OFFSET,
85 __GLOB_ALTDIRFUNC_OFFSET,
86 __GLOB_NOMAGIC_OFFSET,
87 /*
88 * This MinGW implementation DOES add support for the following
89 * custom options, which offer improved handling of MS-Windows
90 * specific peculiarities:--
91 *
92 * GLOB_CASEMATCH makes glob() respect case sensitivity
93 * in path name matches; this is similar
94 * to default behaviour on POSIX systems,
95 * but to better support the MS-Windows
96 * file system, the MinGW implementation
97 * of glob() performs a CASE INSENSITIVE
98 * character match by default, (except
99 * when matching within character group
100 * patterns, which are ALWAYS assumed to
101 * require CASE SENSITIVE matching).
102 */
103 __GLOB_CASEMATCH_OFFSET,
104 /*
105 * The following is a convenience, to mark the end of the enumeration;
106 * it is NEVER used to locate any user visible __GLOB_FLAG__, but it
107 * MUST remain as the final entry in the enumerated list.
108 */
109 __GLOB_FLAG_OFFSET_HIGH_WATER_MARK
110 };
111
112 /* Definitions of the mandatory flags, as specified by POSIX.
113 */
114 #define GLOB_APPEND __GLOB_FLAG__(APPEND)
115 #define GLOB_DOOFFS __GLOB_FLAG__(DOOFFS)
116 #define GLOB_ERR __GLOB_FLAG__(ERR)
117 #define GLOB_MARK __GLOB_FLAG__(MARK)
118 #define GLOB_NOCHECK __GLOB_FLAG__(NOCHECK)
119 #define GLOB_NOESCAPE __GLOB_FLAG__(NOESCAPE)
120 #define GLOB_NOSORT __GLOB_FLAG__(NOSORT)
121
122 /* Additional flags definitions, for MinGW specific extensions.
123 */
124 #define GLOB_CASEMATCH __GLOB_FLAG__(CASEMATCH)
125
126 BEGIN_C_DECLS
127 /*
128 * Function prototypes. Formally POSIX mandates:
129 *
130 * int glob( const char *, int, int (*)( const char *, int ), glob_t * );
131 * void globfree( glob_t * );
132 *
133 * However, our actual function implementations are provided via this
134 * pair of reserved function names...
135 */
136 int __mingw_glob( const char *, int, int (*)( const char *, int ), glob_t * );
137 void __mingw_globfree( glob_t * );
138
139 /* ...to which the standard names are then mapped as aliases,
140 * via inline function expansion.
141 */
142 #define GLOB_INLINE static __inline__ __attribute__((__always_inline__))
143
glob(const char * __pattern,int __flags,int (* __errfunc)(),glob_t * __data)144 GLOB_INLINE int glob
145 ( const char *__pattern, int __flags, int (*__errfunc)(), glob_t *__data )
146 { return __mingw_glob( __pattern, __flags, __errfunc, __data ); }
147
globfree(glob_t * __data)148 GLOB_INLINE void globfree( glob_t *__data )
149 { return __mingw_globfree( __data ); }
150
151 END_C_DECLS
152
153 /* Manifest definitions for the possible status values
154 * which glob() may return.
155 */
156 #define GLOB_SUCCESS (0)
157 #define GLOB_ABORTED (1)
158 #define GLOB_NOMATCH (2)
159 #define GLOB_NOSPACE (3)
160
161 #endif /* ! RC_INVOKED */
162 #endif /* ! defined _GLOB_H */
163