xapian-core  2.0.0
safesysstat.h
Go to the documentation of this file.
1 
4 /* Copyright (C) 2007,2012,2017 Olly Betts
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License as
8  * published by the Free Software Foundation; either version 2 of the
9  * License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, see
18  * <https://www.gnu.org/licenses/>.
19  */
20 
21 #ifndef XAPIAN_INCLUDED_SAFESYSSTAT_H
22 #define XAPIAN_INCLUDED_SAFESYSSTAT_H
23 
24 #include <sys/stat.h>
25 #include <sys/types.h>
26 
27 #ifdef __WIN32__
28 
29 // MSVC lacks these POSIX macros and other compilers may too:
30 #ifndef S_ISDIR
31 # define S_ISDIR(ST_MODE) (((ST_MODE) & _S_IFMT) == _S_IFDIR)
32 #endif
33 #ifndef S_ISREG
34 # define S_ISREG(ST_MODE) (((ST_MODE) & _S_IFMT) == _S_IFREG)
35 #endif
36 
37 // On UNIX, mkdir() is prototyped in <sys/stat.h> but on Windows it's in
38 // <direct.h>, so just include that from here to avoid build failures on
39 // MSVC just because of some new use of mkdir(). This also reduces the
40 // number of conditionalised #include statements we need in the sources.
41 #include <direct.h>
42 
43 // Add overloaded version of mkdir which takes an (ignored) mode argument
44 // to allow source code to just specify a mode argument unconditionally.
45 //
46 // The () around mkdir are in case it's defined as a macro.
47 inline int (mkdir)(const char *pathname, mode_t /*mode*/) {
48  return _mkdir(pathname);
49 }
50 
51 #else
52 
53 // These were specified by POSIX.1-1996, so most platforms should have
54 // these by now:
55 #ifndef S_ISDIR
56 # define S_ISDIR(ST_MODE) (((ST_MODE) & S_IFMT) == S_IFDIR)
57 #endif
58 #ifndef S_ISREG
59 # define S_ISREG(ST_MODE) (((ST_MODE) & S_IFMT) == S_IFREG)
60 #endif
61 
62 #endif
63 
64 #endif /* XAPIAN_INCLUDED_SAFESYSSTAT_H */