xref: /sqlite-3.40.0/src/test_windirent.h (revision 176b3a09)
1 /*
2 ** 2015 November 30
3 **
4 ** The author disclaims copyright to this source code.  In place of
5 ** a legal notice, here is a blessing:
6 **
7 **    May you do good and not evil.
8 **    May you find forgiveness for yourself and forgive others.
9 **    May you share freely, never taking more than you give.
10 **
11 *************************************************************************
12 ** This file contains declarations for most of the opendir() family of
13 ** POSIX functions on Win32 using the MSVCRT.
14 */
15 
16 #if defined(_WIN32) && defined(_MSC_VER) && !defined(SQLITE_WINDIRENT_H)
17 #define SQLITE_WINDIRENT_H
18 
19 /*
20 ** We need several data types from the Windows SDK header.
21 */
22 
23 #ifndef WIN32_LEAN_AND_MEAN
24 #define WIN32_LEAN_AND_MEAN
25 #endif
26 
27 #include "windows.h"
28 
29 /*
30 ** We need several support functions from the SQLite core.
31 */
32 
33 #include "sqlite3.h"
34 
35 /*
36 ** We need several things from the ANSI and MSVCRT headers.
37 */
38 
39 #include <stdio.h>
40 #include <stdlib.h>
41 #include <errno.h>
42 #include <io.h>
43 #include <limits.h>
44 #include <sys/types.h>
45 #include <sys/stat.h>
46 
47 /*
48 ** We may need several defines that should have been in "sys/stat.h".
49 */
50 
51 #ifndef S_ISREG
52 #define S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG)
53 #endif
54 
55 #ifndef S_ISDIR
56 #define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR)
57 #endif
58 
59 #ifndef S_ISLNK
60 #define S_ISLNK(mode) (0)
61 #endif
62 
63 /*
64 ** We may need to provide the "mode_t" type.
65 */
66 
67 #ifndef MODE_T_DEFINED
68   #define MODE_T_DEFINED
69   typedef unsigned short mode_t;
70 #endif
71 
72 /*
73 ** We may need to provide the "ino_t" type.
74 */
75 
76 #ifndef INO_T_DEFINED
77   #define INO_T_DEFINED
78   typedef unsigned short ino_t;
79 #endif
80 
81 /*
82 ** We need to define "NAME_MAX" if it was not present in "limits.h".
83 */
84 
85 #ifndef NAME_MAX
86 #  ifdef FILENAME_MAX
87 #    define NAME_MAX (FILENAME_MAX)
88 #  else
89 #    define NAME_MAX (260)
90 #  endif
91 #endif
92 
93 /*
94 ** We need to define "NULL_INTPTR_T" and "BAD_INTPTR_T".
95 */
96 
97 #ifndef NULL_INTPTR_T
98 #  define NULL_INTPTR_T ((intptr_t)(0))
99 #endif
100 
101 #ifndef BAD_INTPTR_T
102 #  define BAD_INTPTR_T ((intptr_t)(-1))
103 #endif
104 
105 /*
106 ** We need to provide the necessary structures and related types.
107 */
108 
109 #ifndef DIRENT_DEFINED
110 #define DIRENT_DEFINED
111 typedef struct DIRENT DIRENT;
112 typedef DIRENT *LPDIRENT;
113 struct DIRENT {
114   ino_t d_ino;               /* Sequence number, do not use. */
115   unsigned d_attributes;     /* Win32 file attributes. */
116   char d_name[NAME_MAX + 1]; /* Name within the directory. */
117 };
118 #endif
119 
120 #ifndef DIR_DEFINED
121 #define DIR_DEFINED
122 typedef struct DIR DIR;
123 typedef DIR *LPDIR;
124 struct DIR {
125   intptr_t d_handle; /* Value returned by "_findfirst". */
126   DIRENT d_first;    /* DIRENT constructed based on "_findfirst". */
127   DIRENT d_next;     /* DIRENT constructed based on "_findnext". */
128 };
129 #endif
130 
131 /*
132 ** Provide a macro, for use by the implementation, to determine if a
133 ** particular directory entry should be skipped over when searching for
134 ** the next directory entry that should be returned by the readdir() or
135 ** readdir_r() functions.
136 */
137 
138 #ifndef is_filtered
139 #  define is_filtered(a) ((((a).attrib)&_A_HIDDEN) || (((a).attrib)&_A_SYSTEM))
140 #endif
141 
142 /*
143 ** Provide the function prototype for the POSIX compatiable getenv()
144 ** function.  This function is not thread-safe.
145 */
146 
147 extern const char *windirent_getenv(const char *name);
148 
149 /*
150 ** Finally, we can provide the function prototypes for the opendir(),
151 ** readdir(), readdir_r(), and closedir() POSIX functions.
152 */
153 
154 extern LPDIR opendir(const char *dirname);
155 extern LPDIRENT readdir(LPDIR dirp);
156 extern INT readdir_r(LPDIR dirp, LPDIRENT entry, LPDIRENT *result);
157 extern INT closedir(LPDIR dirp);
158 
159 #endif /* defined(WIN32) && defined(_MSC_VER) */
160