Remove unused header include
[xapian.git] / xapian-core / common / safesysstat.h
blobf3f53700f58ab914b930b3430d8fb8dd1287a2ca
1 /** @file safesysstat.h
2 * @brief #include <sys/stat.h>, but enabling large file support.
3 */
4 /* Copyright (C) 2007,2012 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
19 * USA
22 #ifndef XAPIAN_INCLUDED_SAFESYSSTAT_H
23 #define XAPIAN_INCLUDED_SAFESYSSTAT_H
25 #include <sys/stat.h>
27 // For most platforms, AC_SYS_LARGEFILE enables support for large files at
28 // configure time, but MSVC doesn't use configure so we have to put the
29 // magic somewhere else - i.e. here!
31 #ifdef _MSC_VER
32 // MSVC needs to call _stati64() instead of stat() and the struct which holds
33 // the information is "struct _stati64" instead of "struct stat" so we just
34 // use #define to replace both in one go. We also want to use _fstati64()
35 // instead of fstat() but in this case we can use a function-like macro.
37 // This hack is a problem is we ever want a method called "stat", or one called
38 // fstat which takes 2 parameters, but we can probably live with these
39 // limitations.
41 #ifdef stat
42 # undef stat
43 #endif
45 #ifdef fstat
46 # undef fstat
47 #endif
49 // NB: _stati64 not _stat64 (the latter just returns a 64 bit timestamp).
50 #define stat _stati64
51 #define fstat(FD, BUF) _fstati64(FD,BUF)
53 #endif
55 #ifdef __WIN32__
57 // MSVC lacks these POSIX macros and other compilers may too:
58 #ifndef S_ISDIR
59 # define S_ISDIR(ST_MODE) (((ST_MODE) & _S_IFMT) == _S_IFDIR)
60 #endif
61 #ifndef S_ISREG
62 # define S_ISREG(ST_MODE) (((ST_MODE) & _S_IFMT) == _S_IFREG)
63 #endif
65 // On UNIX, mkdir() is prototyped in <sys/stat.h> but on Windows it's in
66 // <direct.h>, so just include that from here to avoid build failures on
67 // MSVC just because of some new use of mkdir(). This also reduces the
68 // number of conditionalised #include statements we need in the sources.
69 #include <direct.h>
71 // Add overloaded version of mkdir which takes an (ignored) mode argument
72 // to allow source code to just specify a mode argument unconditionally.
74 // The () around mkdir are in case it's defined as a macro.
75 inline int (mkdir)(const char *pathname, mode_t /*mode*/) {
76 return _mkdir(pathname);
79 #else
81 // These were specified by POSIX.1-1996, so most platforms should have
82 // these by now:
83 #ifndef S_ISDIR
84 # define S_ISDIR(ST_MODE) (((ST_MODE) & S_IFMT) == S_IFDIR)
85 #endif
86 #ifndef S_ISREG
87 # define S_ISREG(ST_MODE) (((ST_MODE) & S_IFMT) == S_IFREG)
88 #endif
90 #endif
92 #endif /* XAPIAN_INCLUDED_SAFESYSSTAT_H */