common/safefcntl.h

Go to the documentation of this file.
00001 /* safefcntl.h: #include <fcntl.h>, but working around broken platforms.
00002  *
00003  * Copyright (C) 2006,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_SAFEFCNTL_H
00022 #define XAPIAN_INCLUDED_SAFEFCNTL_H
00023 
00024 #include <fcntl.h>
00025 
00026 #if defined __cplusplus && defined open
00027 
00028 // On some versions of Solaris, fcntl.h pollutes the namespace by #define-ing
00029 // "open" to "open64" when largefile support is enabled.  This causes problems
00030 // if you have a method called "open" (other symbols are also #define-d
00031 // e.g. "creat" to "creat64", but only "open" is a problem for Xapian so
00032 // that's the only one we currently fix).
00033 
00034 #ifdef _MSC_VER
00035 // MSVC #define-s open but also defines a function called open, so just undef
00036 // the macro.
00037 # undef open
00038 #else
00039 
00040 inline int fcntl_open_(const char *filename, int flags, mode_t mode) {
00041     return open(filename, flags, mode);
00042 }
00043 
00044 inline int fcntl_open_(const char *filename, int flags) {
00045     return open(filename, flags);
00046 }
00047 
00048 #undef open
00049 
00050 inline int open(const char *filename, int flags, mode_t mode) {
00051     return fcntl_open_(filename, flags, mode);
00052 }
00053 
00054 inline int open(const char *filename, int flags) {
00055     return fcntl_open_(filename, flags);
00056 }
00057 
00058 #endif
00059 
00060 #endif
00061 
00062 // O_BINARY is only useful for platforms like Windows which distinguish between
00063 // text and binary files, but it's cleaner to define it to 0 here for other
00064 // platforms so we can avoid #ifdef where we need to use it in the code.
00065 #ifndef __WIN32__
00066 # ifndef O_BINARY
00067 #  define O_BINARY 0
00068 # endif
00069 #endif
00070 
00071 #endif /* XAPIAN_INCLUDED_SAFEFCNTL_H */

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