1 /* /////////////////////////////////////////////////////////////////////////
2  * File:    glob.h
3  *
4  * Purpose: Declaration of the glob() API functions and types for the
5  *          Win32 platform.
6  *
7  * Created: 13th November 2002
8  * Updated: 5th February 2010
9  *
10  * Home:    http://synesis.com.au/software/
11  *
12  * Copyright (c) 2002-2010, Matthew Wilson and Synesis Software
13  * All rights reserved.
14  *
15  * Redistribution and use in source and binary forms, with or without
16  * modification, are permitted provided that the following conditions are met:
17  *
18  * - Redistributions of source code must retain the above copyright notice, this
19  *   list of conditions and the following disclaimer.
20  * - Redistributions in binary form must reproduce the above copyright notice,
21  *   this list of conditions and the following disclaimer in the documentation
22  *   and/or other materials provided with the distribution.
23  * - Neither the names of Matthew Wilson and Synesis Software nor the names of
24  *   any contributors may be used to endorse or promote products derived from
25  *   this software without specific prior written permission.
26  *
27  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
28  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
30  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
31  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37  * POSSIBILITY OF SUCH DAMAGE.
38  *
39  * ////////////////////////////////////////////////////////////////////// */
40 
41 
42 /** \file glob.h
43  *
44  * Contains the declarations for the glob() API.
45  */
46 
47 #ifndef SYNSOFT_UNIXEM_INCL_H_GLOB
48 #define SYNSOFT_UNIXEM_INCL_H_GLOB
49 
50 #include "leak_dumper.h"
51 
52 /* ////////////////////////////////////////////////////////////////////// */
53 
54 /** \weakgroup unixem Synesis Software UNIX Emulation for Win32
55  * \brief The UNIX emulation library
56  */
57 
58 /** \weakgroup unixem_glob glob() API
59  * \ingroup UNIXem unixem
60  * \brief This API provides facilities for enumerating the file-system contents
61  * @{
62  */
63 
64 /* ////////////////////////////////////////////////////////////////////// */
65 
66 #ifndef _WIN32
67 # error This file is only currently defined for compilation on Win32 systems
68 #endif /* _WIN32 */
69 
70 /* /////////////////////////////////////////////////////////////////////////
71  * Constants and definitions
72  */
73 
74 /* Error codes */
75 #define GLOB_NOSPACE    (1)             /*!< \brief (Error result code:) An attempt to allocate memory failed, or if errno was 0 GLOB_LIMIT was specified in the flags and ARG_MAX patterns were matched. */
76 #define GLOB_ABORTED    (2)             /*!< \brief (Error result code:) The scan was stopped because an error was encountered and either GLOB_ERR was set or (*errfunc)() returned non-zero. */
77 #define GLOB_NOMATCH    (3)             /*!< \brief (Error result code:) The pattern does not match any existing pathname, and GLOB_NOCHECK was not set int flags. */
78 #define GLOB_NOSYS      (4)             /*!< \brief (Error result code:) . */
79 #define GLOB_ABEND      GLOB_ABORTED    /*!< \brief (Error result code:) . */
80 
81 /* Flags */
82 #define GLOB_ERR            0x00000001  /*!< \brief Return on read errors. */
83 #define GLOB_MARK           0x00000002  /*!< \brief Append a slash to each name. */
84 #define GLOB_NOSORT         0x00000004  /*!< \brief Don't sort the names. */
85 #define GLOB_DOOFFS         0x00000008  /*!< \brief Insert PGLOB->gl_offs NULLs. Supported from version 1.6 of UNIXem. */
86 #define GLOB_NOCHECK        0x00000010  /*!< \brief If nothing matches, return the pattern. Supported from version 1.6 of UNIXem. */
87 #define GLOB_APPEND         0x00000020  /*!< \brief Append to results of a previous call. Not currently supported in this implementation. */
88 #define GLOB_NOESCAPE       0x00000040  /*!< \brief Backslashes don't quote metacharacters. Has no effect in this implementation, since escaping is not supported. */
89 
90 #define GLOB_PERIOD         0x00000080  /*!< \brief Leading `.' can be matched by metachars. Supported from version 1.6 of UNIXem. */
91 #define GLOB_MAGCHAR        0x00000100  /*!< \brief Set in gl_flags if any metachars seen. Supported from version 1.6 of UNIXem. */
92 /* #define GLOB_ALTDIRFUNC     0x00000200 */  /*!< \brief Use gl_opendir et al functions. Not currently supported in this implementation. */
93 /* #define GLOB_BRACE          0x00000400 */  /*!< \brief Expand "{a,b}" to "a" "b". Not currently supported in this implementation. */
94 #define GLOB_NOMAGIC        0x00000800  /*!< \brief If no magic chars, return the pattern. Supported from version 1.6 of UNIXem. */
95 #define GLOB_TILDE          0x00001000  /*!< \brief Expand ~user and ~ to home directories. Partially supported from version 1.6 of UNIXem: leading ~ is expanded to %HOMEDRIVE%%HOMEPATH%. */
96 #define GLOB_ONLYDIR        0x00002000  /*!< \brief Match only directories. This implementation guarantees to only return directories when this flag is specified. */
97 #define GLOB_TILDE_CHECK    0x00004000  /*!< \brief Like GLOB_TILDE but return an GLOB_NOMATCH even if GLOB_NOCHECK specified. Supported from version 1.6 of UNIXem. */
98 #define GLOB_ONLYFILE       0x00008000  /*!< \brief Match only files. Supported from version 1.6 of UNIXem. */
99 #define GLOB_NODOTSDIRS     0x00010000  /*!< \brief Elide "." and ".." directories from wildcard searches. Supported from version 1.6 of UNIXem. */
100 #define GLOB_LIMIT          0x00020000  /*!< \brief Limits the search to the number specified by the caller in gl_matchc. Supported from version 1.6 of UNIXem. */
101 
102 /* /////////////////////////////////////////////////////////////////////////
103  * Typedefs
104  */
105 
106 /** \brief Result structure for glob()
107  *
108  * This structure is used by glob() to return the results of the search.
109  */
110 typedef struct
111 {
112   int   gl_pathc;   /*!< count of total paths so far */
113   int   gl_matchc;  /*!< count of paths matching pattern */
114   int   gl_offs;    /*!< reserved at beginning of gl_pathv */
115   int   gl_flags;   /*!< returned flags */
116   char  **gl_pathv; /*!< list of paths matching pattern */
117 } glob_t;
118 
119 /* /////////////////////////////////////////////////////////////////////////
120  * API functions
121  */
122 
123 #ifdef __cplusplus
124 extern "C" {
125 #endif /* __cplusplus */
126 
127 /** \brief Generates pathnames matching a pattern
128  *
129  * This function is a pathname generator that implements the rules for
130  * file name pattern matching used by the UNIX shell.
131  *
132  * \param pattern The pattern controlling the search
133  * \param flags A combination of the <b>GLOB_*</b> flags
134  * \param errfunc A function that is called each time part of the search processing fails
135  * \param pglob Pointer to a glob_t structure to receive the search results
136  * \return 0 on success, otherwise one of the <b>GLOB_*</b> error codes
137  */
138 int glob( char const  *pattern
139         , int         flags
140 #if defined(__COMO__)
141         , int       (*errfunc)(char const *, int)
142 #else /* ? compiler */
143         , const int (*errfunc)(char const *, int)
144 #endif /* compiler */
145         , glob_t      *pglob);
146 
147 /** \brief Frees the results of a call to glob
148  *
149  * This function releases any memory allocated in a call to glob. It must
150  * always be called for a successful call to glob.
151  *
152  * \param pglob Pointer to a glob_t structure to receive the search results
153  */
154 void globfree(glob_t *pglob);
155 
156 #ifdef __cplusplus
157 }
158 #endif /* __cplusplus */
159 
160 /* ////////////////////////////////////////////////////////////////////// */
161 
162 /** @} // end of group unixem_glob */
163 
164 /* ////////////////////////////////////////////////////////////////////// */
165 
166 #endif /* SYNSOFT_UNIXEM_INCL_H_GLOB */
167 
168 /* ///////////////////////////// end of file //////////////////////////// */
169