1 /** @file 2 * @brief #include <sys/stat.h> with portability enhancements 3 */ 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, write to the Free Software 18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 19 * USA 20 */ 21 22 #ifndef XAPIAN_INCLUDED_SAFESYSSTAT_H 23 #define XAPIAN_INCLUDED_SAFESYSSTAT_H 24 25 #include <sys/stat.h> 26 #include <sys/types.h> 27 28 #ifdef __WIN32__ 29 30 // MSVC lacks these POSIX macros and other compilers may too: 31 #ifndef S_ISDIR 32 # define S_ISDIR(ST_MODE) (((ST_MODE) & _S_IFMT) == _S_IFDIR) 33 #endif 34 #ifndef S_ISREG 35 # define S_ISREG(ST_MODE) (((ST_MODE) & _S_IFMT) == _S_IFREG) 36 #endif 37 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. 42 #include <direct.h> 43 44 // Add overloaded version of mkdir which takes an (ignored) mode argument 45 // to allow source code to just specify a mode argument unconditionally. 46 // 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); 50 } 51 52 #else 53 54 // These were specified by POSIX.1-1996, so most platforms should have 55 // these by now: 56 #ifndef S_ISDIR 57 # define S_ISDIR(ST_MODE) (((ST_MODE) & S_IFMT) == S_IFDIR) 58 #endif 59 #ifndef S_ISREG 60 # define S_ISREG(ST_MODE) (((ST_MODE) & S_IFMT) == S_IFREG) 61 #endif 62 63 #endif 64 65 #endif /* XAPIAN_INCLUDED_SAFESYSSTAT_H */ 66