OSDN Git Service

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