Prepared windows port by removing a number of spurious reference to unix-specific interfaces, and using some xapian posix adaptor includes

This commit is contained in:
Jean-Francois Dockes
2015-08-19 14:41:10 +02:00
parent 14ab6909f3
commit c6e228b7c6
37 changed files with 566 additions and 382 deletions
+71
View File
@@ -0,0 +1,71 @@
/* safefcntl.h: #include <fcntl.h>, but working around broken platforms.
*
* Copyright (C) 2006,2007 Olly Betts
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
* USA
*/
#ifndef XAPIAN_INCLUDED_SAFEFCNTL_H
#define XAPIAN_INCLUDED_SAFEFCNTL_H
#include <fcntl.h>
#if defined __cplusplus && defined open
// On some versions of Solaris, fcntl.h pollutes the namespace by #define-ing
// "open" to "open64" when largefile support is enabled. This causes problems
// if you have a method called "open" (other symbols are also #define-d
// e.g. "creat" to "creat64", but only "open" is a problem for Xapian so
// that's the only one we currently fix).
#ifdef _MSC_VER
// MSVC #define-s open but also defines a function called open, so just undef
// the macro.
# undef open
#else
inline int fcntl_open_(const char *filename, int flags, mode_t mode) {
return open(filename, flags, mode);
}
inline int fcntl_open_(const char *filename, int flags) {
return open(filename, flags);
}
#undef open
inline int open(const char *filename, int flags, mode_t mode) {
return fcntl_open_(filename, flags, mode);
}
inline int open(const char *filename, int flags) {
return fcntl_open_(filename, flags);
}
#endif
#endif
// O_BINARY is only useful for platforms like Windows which distinguish between
// text and binary files, but it's cleaner to define it to 0 here for other
// platforms so we can avoid #ifdef where we need to use it in the code.
#ifndef __WIN32__
# ifndef O_BINARY
# define O_BINARY 0
# endif
#endif
#endif /* XAPIAN_INCLUDED_SAFEFCNTL_H */
+91
View File
@@ -0,0 +1,91 @@
/* safesysstat.h: #include <sys/stat.h>, but enabling large file support.
*
* Copyright (C) 2007,2012 Olly Betts
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
* USA
*/
#ifndef XAPIAN_INCLUDED_SAFESYSSTAT_H
#define XAPIAN_INCLUDED_SAFESYSSTAT_H
#include <sys/stat.h>
// For most platforms, AC_SYS_LARGEFILE enables support for large files at
// configure time, but MSVC doesn't use configure so we have to put the
// magic somewhere else - i.e. here!
#ifdef _MSC_VER
// MSVC needs to call _stati64() instead of stat() and the struct which holds
// the information is "struct _stati64" instead of "struct stat" so we just
// use #define to replace both in one go. We also want to use _fstati64()
// instead of fstat() but in this case we can use a function-like macro.
//
// This hack is a problem is we ever want a method called "stat", or one called
// fstat which takes 2 parameters, but we can probably live with these
// limitations.
#ifdef stat
# undef stat
#endif
#ifdef fstat
# undef fstat
#endif
// NB: _stati64 not _stat64 (the latter just returns a 64 bit timestamp).
#define stat _stati64
#define fstat(FD, BUF) _fstati64(FD,BUF)
#endif
#ifdef __WIN32__
// MSVC lacks these POSIX macros and other compilers may too:
#ifndef S_ISDIR
# define S_ISDIR(ST_MODE) (((ST_MODE) & _S_IFMT) == _S_IFDIR)
#endif
#ifndef S_ISREG
# define S_ISREG(ST_MODE) (((ST_MODE) & _S_IFMT) == _S_IFREG)
#endif
// On UNIX, mkdir() is prototyped in <sys/stat.h> but on Windows it's in
// <direct.h>, so just include that from here to avoid build failures on
// MSVC just because of some new use of mkdir(). This also reduces the
// number of conditionalised #include statements we need in the sources.
#include <direct.h>
// Add overloaded version of mkdir which takes an (ignored) mode argument
// to allow source code to just specify a mode argument unconditionally.
//
// The () around mkdir are in case it's defined as a macro.
inline int (mkdir)(const char *pathname, mode_t /*mode*/) {
return _mkdir(pathname);
}
#else
// These were specified by POSIX.1-1996, so most platforms should have
// these by now:
#ifndef S_ISDIR
# define S_ISDIR(ST_MODE) (((ST_MODE) & S_IFMT) == S_IFDIR)
#endif
#ifndef S_ISREG
# define S_ISREG(ST_MODE) (((ST_MODE) & S_IFMT) == S_IFREG)
#endif
#endif
#endif /* XAPIAN_INCLUDED_SAFESYSSTAT_H */
+78
View File
@@ -0,0 +1,78 @@
/* safeunistd.h: <unistd.h>, but with compat. and large file support for MSVC.
*
* Copyright (C) 2007 Olly Betts
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
* USA
*/
#ifndef XAPIAN_INCLUDED_SAFEUNISTD_H
#define XAPIAN_INCLUDED_SAFEUNISTD_H
#ifndef _MSC_VER
# include <unistd.h>
#else
// sys/types.h has a typedef for off_t so make sure we've seen that before
// we hide it behind a #define.
# include <sys/types.h>
// MSVC doesn't even HAVE unistd.h - io.h seems the nearest equivalent.
// We also need to do some renaming of functions to get versions which
// work on large files.
# include <io.h>
# ifdef lseek
# undef lseek
# endif
# ifdef off_t
# undef off_t
# endif
# define lseek(FD, OFF, WHENCE) _lseeki64(FD, OFF, WHENCE)
# define off_t __int64
// process.h is needed for getpid().
# include <process.h>
#endif
#ifdef __WIN32__
inline unsigned int
sleep(unsigned int seconds)
{
// Use our own little helper function to avoid pulling in <windows.h>.
extern void xapian_sleep_milliseconds(unsigned int millisecs);
// Sleep takes a time interval in milliseconds, whereas POSIX sleep takes
// a time interval in seconds, so we need to multiply 'seconds' by 1000.
//
// But make sure the multiplication won't overflow! 4294967 seconds is
// nearly 50 days, so just sleep for that long and return the number of
// seconds left to sleep for. The common case of sleep(CONSTANT) should
// optimise to just xapian_sleep_milliseconds(CONSTANT).
if (seconds > 4294967u) {
xapian_sleep_milliseconds(4294967000u);
return seconds - 4294967u;
}
xapian_sleep_milliseconds(seconds * 1000u);
return 0;
}
#endif
#endif /* XAPIAN_INCLUDED_SAFEUNISTD_H */