2 * @brief <unistd.h>, but with compat. and large file support for MSVC.
4 /* Copyright (C) 2007,2015 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
22 #ifndef XAPIAN_INCLUDED_SAFEUNISTD_H
23 #define XAPIAN_INCLUDED_SAFEUNISTD_H
29 // sys/types.h has a typedef for off_t so make sure we've seen that before
30 // we hide it behind a #define.
31 # include <sys/types.h>
33 // MSVC doesn't even HAVE unistd.h - io.h seems the nearest equivalent.
34 // We also need to do some renaming of functions to get versions which
35 // work on large files.
46 # define lseek(FD, OFF, WHENCE) _lseeki64(FD, OFF, WHENCE)
47 # define off_t __int64
49 // process.h is needed for getpid().
54 // Under mingw we probably don't need to provide our own sleep().
55 #if defined __WIN32__ && !defined HAVE_SLEEP
58 sleep(unsigned int seconds
)
60 // Use our own little helper function to avoid pulling in <windows.h>.
61 extern void xapian_sleep_milliseconds(unsigned int millisecs
);
63 // Sleep takes a time interval in milliseconds, whereas POSIX sleep takes
64 // a time interval in seconds, so we need to multiply 'seconds' by 1000.
66 // But make sure the multiplication won't overflow! 4294967 seconds is
67 // nearly 50 days, so just sleep for that long and return the number of
68 // seconds left to sleep for. The common case of sleep(CONSTANT) should
69 // optimise to just xapian_sleep_milliseconds(CONSTANT).
70 if (seconds
> 4294967u) {
71 xapian_sleep_milliseconds(4294967000u);
72 return seconds
- 4294967u;
74 xapian_sleep_milliseconds(seconds
* 1000u);
80 #endif /* XAPIAN_INCLUDED_SAFEUNISTD_H */