Remove special handling of open on MSVC
[xapian.git] / xapian-core / common / safefcntl.h
blob50945c7053669239683163f7b46d03785088118e
1 /** @file safefcntl.h
2 * @brief #include <fcntl.h>, but working around broken platforms.
3 */
4 /* Copyright (C) 2006,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_SAFEFCNTL_H
23 #define XAPIAN_INCLUDED_SAFEFCNTL_H
25 #include <fcntl.h>
27 #if defined __cplusplus && defined open
29 // On some versions of Solaris, fcntl.h pollutes the namespace by #define-ing
30 // "open" to "open64" when largefile support is enabled. This causes problems
31 // if you have a method called "open" (other symbols are also #define-d
32 // e.g. "creat" to "creat64", but only "open" is a problem for Xapian so
33 // that's the only one we currently fix).
35 inline int fcntl_open_(const char *filename, int flags, mode_t mode) {
36 return open(filename, flags, mode);
39 inline int fcntl_open_(const char *filename, int flags) {
40 return open(filename, flags);
43 #undef open
45 inline int open(const char *filename, int flags, mode_t mode) {
46 return fcntl_open_(filename, flags, mode);
49 inline int open(const char *filename, int flags) {
50 return fcntl_open_(filename, flags);
53 #endif
55 // O_BINARY is only useful for platforms like Windows which distinguish between
56 // text and binary files, but it's cleaner to define it to 0 here for other
57 // platforms so we can avoid #ifdef where we need to use it in the code.
58 #ifndef __WIN32__
59 # ifndef O_BINARY
60 # define O_BINARY 0
61 # endif
62 #endif
64 // If O_CLOEXEC isn't supported, we probably can't mark fds as close-on-exec.
65 #ifndef O_CLOEXEC
66 # define O_CLOEXEC 0
67 #endif
69 #endif /* XAPIAN_INCLUDED_SAFEFCNTL_H */