|
|
@@ -65,6 +65,19 @@
|
|
|
#include <unistd.h>
|
|
|
#endif
|
|
|
|
|
|
+#ifndef WIN_NT
|
|
|
+#include <dirent.h>
|
|
|
+#include <sys/mman.h>
|
|
|
+#include <sys/resource.h>
|
|
|
+#else
|
|
|
+#include <io.h>
|
|
|
+#endif
|
|
|
+
|
|
|
+#include <stdio.h>
|
|
|
+#include <errno.h>
|
|
|
+#include <fcntl.h>
|
|
|
+#include <sys/stat.h>
|
|
|
+
|
|
|
#if defined(_POSIX_THREADS) && _POSIX_THREADS >= 200112L && !defined(WIN_NT)
|
|
|
// above check is generally true. However, we use pthreads on some platforms
|
|
|
// where _POSIX_THREADS is defined to "1" or not even defined at all!
|
|
|
@@ -869,8 +882,252 @@ void GDS_breakpoint(int);
|
|
|
|
|
|
/* The default lseek offset type. Changed from nothing to (off_t) to correctly support 64 bit IO */
|
|
|
#ifndef LSEEK_OFFSET_CAST
|
|
|
+#ifdef LSB_BUILD
|
|
|
+#define LSEEK_OFFSET_CAST (loff_t)
|
|
|
+#else
|
|
|
#define LSEEK_OFFSET_CAST (off_t)
|
|
|
#endif
|
|
|
+#endif
|
|
|
+
|
|
|
+// LSB uses 32bit IO functions by default
|
|
|
+#ifdef LSB_BUILD
|
|
|
+#define off_t loff_t
|
|
|
+#define fpos_t fpos64_t
|
|
|
+#define dirent dirent64
|
|
|
+#define rlimit rlimit64
|
|
|
+#define STAT stat64
|
|
|
+#define FSTAT fstat64
|
|
|
+#define LSTAT lstat64
|
|
|
+#define FLOCK flock64
|
|
|
+#else
|
|
|
+#define STAT stat
|
|
|
+#define FSTAT fstat
|
|
|
+#define LSTAT lstat
|
|
|
+#define LSTAT lstat
|
|
|
+#define FLOCK flock
|
|
|
+#endif
|
|
|
+
|
|
|
+#ifdef WIN_NT
|
|
|
+#define mode_t int
|
|
|
+#endif
|
|
|
+
|
|
|
+namespace fb_io {
|
|
|
+
|
|
|
+inline int open(const char* pathname, int flags, mode_t mode = 0666) {
|
|
|
+ int rc;
|
|
|
+ do {
|
|
|
+#ifdef LSB_BUILD
|
|
|
+ rc = open64(pathname, flags, mode);
|
|
|
+#else
|
|
|
+ rc = ::open(pathname, flags, mode);
|
|
|
+#endif
|
|
|
+ } while (rc == -1 && SYSCALL_INTERRUPTED(errno));
|
|
|
+ return rc;
|
|
|
+}
|
|
|
+
|
|
|
+inline FILE *fopen(const char *path, const char *mode) {
|
|
|
+ FILE* rc = NULL;
|
|
|
+ do {
|
|
|
+#ifdef LSB_BUILD
|
|
|
+ rc = fopen64(path, mode);
|
|
|
+#else
|
|
|
+ rc = ::fopen(path, mode);
|
|
|
+#endif
|
|
|
+ } while (rc == NULL && SYSCALL_INTERRUPTED(errno));
|
|
|
+ return rc;
|
|
|
+}
|
|
|
+
|
|
|
+inline off_t lseek(int fd, off_t offset, int whence) {
|
|
|
+ off_t rc;
|
|
|
+ do {
|
|
|
+#ifdef LSB_BUILD
|
|
|
+ rc = lseek64(fd, offset, whence);
|
|
|
+#else
|
|
|
+ rc = ::lseek(fd, offset, whence);
|
|
|
+#endif
|
|
|
+ } while (rc == (off_t) -1 && SYSCALL_INTERRUPTED(errno));
|
|
|
+ return rc;
|
|
|
+}
|
|
|
+
|
|
|
+inline int stat(const char *path, struct STAT *buf) {
|
|
|
+ int rc;
|
|
|
+ do {
|
|
|
+#ifdef LSB_BUILD
|
|
|
+ rc = stat64(path, buf);
|
|
|
+#else
|
|
|
+ rc = ::stat(path, buf);
|
|
|
+#endif
|
|
|
+ } while (rc == -1 && SYSCALL_INTERRUPTED(errno));
|
|
|
+ return rc;
|
|
|
+}
|
|
|
+
|
|
|
+inline int fstat(int fd, struct STAT *buf) {
|
|
|
+ int rc;
|
|
|
+ do {
|
|
|
+#ifdef LSB_BUILD
|
|
|
+ rc = fstat64(fd, buf);
|
|
|
+#else
|
|
|
+ rc = ::fstat(fd, buf);
|
|
|
+#endif
|
|
|
+ } while (rc == -1 && SYSCALL_INTERRUPTED(errno));
|
|
|
+ return rc;
|
|
|
+}
|
|
|
+
|
|
|
+inline int fgetpos(FILE *stream, fpos_t *pos) {
|
|
|
+ int rc;
|
|
|
+ do {
|
|
|
+#ifdef LSB_BUILD
|
|
|
+ rc = fgetpos64(stream, pos);
|
|
|
+#else
|
|
|
+ rc = ::fgetpos(stream, pos);
|
|
|
+#endif
|
|
|
+ } while (rc == -1 && SYSCALL_INTERRUPTED(errno));
|
|
|
+ return rc;
|
|
|
+}
|
|
|
+
|
|
|
+inline int fsetpos(FILE *stream, const fpos_t *pos) {
|
|
|
+ int rc;
|
|
|
+ do {
|
|
|
+#ifdef LSB_BUILD
|
|
|
+ rc = fsetpos64(stream, pos);
|
|
|
+#else
|
|
|
+ rc = ::fsetpos(stream, pos);
|
|
|
+#endif
|
|
|
+ } while (rc == -1 && SYSCALL_INTERRUPTED(errno));
|
|
|
+ return rc;
|
|
|
+}
|
|
|
+
|
|
|
+#ifndef WIN_NT
|
|
|
+inline int lockf(int fd, int cmd, off_t len) {
|
|
|
+ int rc;
|
|
|
+ do {
|
|
|
+#ifdef LSB_BUILD
|
|
|
+ rc = lockf64(fd, cmd, len);
|
|
|
+#else
|
|
|
+ rc = ::lockf(fd, cmd, len);
|
|
|
+#endif
|
|
|
+ } while (rc == -1 && SYSCALL_INTERRUPTED(errno));
|
|
|
+ return rc;
|
|
|
+}
|
|
|
+
|
|
|
+inline int mkstemp(char *__template) {
|
|
|
+ int rc;
|
|
|
+ do {
|
|
|
+#ifdef LSB_BUILD
|
|
|
+ rc = mkstemp64(__template);
|
|
|
+#else
|
|
|
+ rc = ::mkstemp(__template);
|
|
|
+#endif
|
|
|
+ } while (rc == -1 && SYSCALL_INTERRUPTED(errno));
|
|
|
+ return rc;
|
|
|
+}
|
|
|
+
|
|
|
+inline ssize_t pread(int fd, void *buf, size_t count, off_t offset) {
|
|
|
+ // Don't check EINTR because it's done by caller
|
|
|
+ return
|
|
|
+#ifdef LSB_BUILD
|
|
|
+ pread64(fd, buf, count, offset);
|
|
|
+#else
|
|
|
+ ::pread(fd, buf, count, offset);
|
|
|
+#endif
|
|
|
+}
|
|
|
+
|
|
|
+inline ssize_t pwrite(int fd, const void *buf, size_t count, off_t offset) {
|
|
|
+ // Don't check EINTR because it's done by caller
|
|
|
+ return
|
|
|
+#ifdef LSB_BUILD
|
|
|
+ pwrite64(fd, buf, count, offset);
|
|
|
+#else
|
|
|
+ ::pwrite(fd, buf, count, offset);
|
|
|
+#endif
|
|
|
+}
|
|
|
+
|
|
|
+inline struct dirent *readdir(DIR *dirp) {
|
|
|
+ struct dirent* rc;
|
|
|
+ do {
|
|
|
+#ifdef LSB_BUILD
|
|
|
+ rc = readdir64(dirp);
|
|
|
+#else
|
|
|
+ rc = ::readdir(dirp);
|
|
|
+#endif
|
|
|
+ } while (rc == NULL && SYSCALL_INTERRUPTED(errno));
|
|
|
+ return rc;
|
|
|
+}
|
|
|
+
|
|
|
+inline void *mmap(void *addr, size_t length, int prot, int flags,
|
|
|
+ int fd, off_t offset) {
|
|
|
+ void* rc;
|
|
|
+ do {
|
|
|
+#ifdef LSB_BUILD
|
|
|
+ rc = mmap64(addr, length, prot, flags, fd, offset);
|
|
|
+#else
|
|
|
+ rc = ::mmap(addr, length, prot, flags, fd, offset);
|
|
|
+#endif
|
|
|
+ } while (rc == MAP_FAILED && SYSCALL_INTERRUPTED(errno));
|
|
|
+ return rc;
|
|
|
+}
|
|
|
+
|
|
|
+inline int ftruncate(int fd, off_t length) {
|
|
|
+ int rc;
|
|
|
+ do {
|
|
|
+#ifdef LSB_BUILD
|
|
|
+ rc = ftruncate64(fd, length);
|
|
|
+#else
|
|
|
+ rc = ::ftruncate(fd, length);
|
|
|
+#endif
|
|
|
+ } while (rc == -1 && SYSCALL_INTERRUPTED(errno));
|
|
|
+ return rc;
|
|
|
+}
|
|
|
+
|
|
|
+inline int lstat(const char *path, struct STAT *buf) {
|
|
|
+ int rc;
|
|
|
+ do {
|
|
|
+#ifdef LSB_BUILD
|
|
|
+ rc = lstat64(path, buf);
|
|
|
+#else
|
|
|
+ rc = ::lstat(path, buf);
|
|
|
+#endif
|
|
|
+ } while (rc == -1 && SYSCALL_INTERRUPTED(errno));
|
|
|
+ return rc;
|
|
|
+}
|
|
|
+
|
|
|
+inline int posix_fadvise(int fd, off_t offset, off_t len, int advice) {
|
|
|
+ int rc;
|
|
|
+ do {
|
|
|
+#ifdef LSB_BUILD
|
|
|
+ rc = posix_fadvise64(fd, offset, len, advice);
|
|
|
+#else
|
|
|
+ rc = ::posix_fadvise(fd, offset, len, advice);
|
|
|
+#endif
|
|
|
+ } while (rc != 0 && SYSCALL_INTERRUPTED(rc));
|
|
|
+ return rc;
|
|
|
+}
|
|
|
+
|
|
|
+inline int getrlimit(int resource, struct rlimit *rlim) {
|
|
|
+ int rc;
|
|
|
+ do {
|
|
|
+#ifdef LSB_BUILD
|
|
|
+ rc = getrlimit64(resource, rlim);
|
|
|
+#else
|
|
|
+ rc = ::getrlimit(resource, rlim);
|
|
|
+#endif
|
|
|
+ } while (rc == -1 && SYSCALL_INTERRUPTED(errno));
|
|
|
+ return rc;
|
|
|
+}
|
|
|
+
|
|
|
+inline int setrlimit(int resource, const struct rlimit *rlim) {
|
|
|
+ int rc;
|
|
|
+ do {
|
|
|
+#ifdef LSB_BUILD
|
|
|
+ rc = setrlimit64(resource, rlim);
|
|
|
+#else
|
|
|
+ rc = ::setrlimit(resource, rlim);
|
|
|
+#endif
|
|
|
+ } while (rc == -1 && SYSCALL_INTERRUPTED(errno));
|
|
|
+ return rc;
|
|
|
+}
|
|
|
+#endif // WIN_NT
|
|
|
+} // namespace fb_io
|
|
|
|
|
|
#define STRINGIZE_AUX(x) #x
|
|
|
#define STRINGIZE(x) STRINGIZE_AUX(x)
|