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