2 * @brief #include <sys/stat.h> with portability enhancements
4 /* Copyright (C) 2007,2012,2017 Olly Betts
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.
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.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
22 #ifndef XAPIAN_INCLUDED_SAFESYSSTAT_H
23 #define XAPIAN_INCLUDED_SAFESYSSTAT_H
26 #include <sys/types.h>
30 // MSVC lacks these POSIX macros and other compilers may too:
32 # define S_ISDIR(ST_MODE) (((ST_MODE) & _S_IFMT) == _S_IFDIR)
35 # define S_ISREG(ST_MODE) (((ST_MODE) & _S_IFMT) == _S_IFREG)
38 // On UNIX, mkdir() is prototyped in <sys/stat.h> but on Windows it's in
39 // <direct.h>, so just include that from here to avoid build failures on
40 // MSVC just because of some new use of mkdir(). This also reduces the
41 // number of conditionalised #include statements we need in the sources.
44 // Add overloaded version of mkdir which takes an (ignored) mode argument
45 // to allow source code to just specify a mode argument unconditionally.
47 // The () around mkdir are in case it's defined as a macro.
48 inline int (mkdir
)(const char *pathname
, mode_t
/*mode*/) {
49 return _mkdir(pathname
);
54 // These were specified by POSIX.1-1996, so most platforms should have
57 # define S_ISDIR(ST_MODE) (((ST_MODE) & S_IFMT) == S_IFDIR)
60 # define S_ISREG(ST_MODE) (((ST_MODE) & S_IFMT) == S_IFREG)
65 #endif /* XAPIAN_INCLUDED_SAFESYSSTAT_H */