common/safesysstat.h

Go to the documentation of this file.
00001 /* safesysstat.h: #include <sys/stat.h>, but enabling large file support.
00002  *
00003  * Copyright (C) 2007 Olly Betts
00004  *
00005  * This program is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU General Public License as
00007  * published by the Free Software Foundation; either version 2 of the
00008  * License, or (at your option) any later version.
00009  *
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program; if not, write to the Free Software
00017  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
00018  * USA
00019  */
00020 
00021 #ifndef XAPIAN_INCLUDED_SAFESYSSTAT_H
00022 #define XAPIAN_INCLUDED_SAFESYSSTAT_H
00023 
00024 #include <sys/stat.h>
00025 
00026 // For most platforms, AC_SYS_LARGEFILE enables support for large files at
00027 // configure time, but MSVC doesn't use configure so we have to put the
00028 // magic somewhere else - i.e. here!
00029 
00030 #ifdef _MSC_VER
00031 // MSVC needs to call _stati64() instead of stat() and the struct which holds
00032 // the information is "struct _stati64" instead of "struct stat" so we just
00033 // use #define to replace both in one go.  We also want to use _fstati64()
00034 // instead of fstat() but in this case we can use a function-like macro.
00035 //
00036 // This hack is a problem is we ever want a method called "stat", or one called
00037 // fstat which takes 2 parameters, but we can probably live with these
00038 // limitations.
00039 
00040 #ifdef stat
00041 # undef stat
00042 #endif
00043 
00044 #ifdef fstat
00045 # undef fstat
00046 #endif
00047 
00048 // NB: _stati64 not _stat64 (the latter just returns a 64 bit timestamp).
00049 #define stat _stati64
00050 #define fstat(FD, BUF) _fstati64(FD,BUF)
00051 #endif
00052 
00053 // MSVC lacks these POSIX macros, and other platforms may too:
00054 #ifndef S_ISDIR
00055 # define S_ISDIR(m) (((m) & _S_IFMT) == _S_IFDIR)
00056 #endif
00057 #ifndef S_ISREG
00058 # define S_ISREG(m) (((m) & _S_IFMT) == _S_IFREG)
00059 #endif
00060 
00061 #ifdef __WIN32__
00062 // On UNIX, mkdir() is prototyped in <sys/stat.h> but in Windows it's in
00063 // <direct.h>, so just include that from here to avoid build failures on
00064 // MSVC just because of some new use of mkdir().  This also reduces the
00065 // number of conditionalised #include statements we need in the sources.
00066 #include <direct.h>
00067 
00068 // Add overloaded version of mkdir which takes an (ignored) mode argument
00069 // to allow source code to just specify a mode argument unconditionally.
00070 inline int (mkdir)(const char *pathname, mode_t /*mode*/) {
00071     return _mkdir(pathname);
00072 }
00073 #endif
00074 
00075 #endif /* XAPIAN_INCLUDED_SAFESYSSTAT_H */

Documentation for Xapian (version 1.0.10).
Generated on 24 Dec 2008 by Doxygen 1.5.2.