From 40681e60379ef8fd3ec89c9019d21b649a976c8a Mon Sep 17 00:00:00 2001 From: vitaut Date: Wed, 6 May 2015 07:29:58 -0700 Subject: [PATCH] Fix compilation of posix-test on MinGW --- test/posix-test.cc | 20 +++++++++++--------- test/posix-test.h | 16 +++++++++++----- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/test/posix-test.cc b/test/posix-test.cc index 453b3bb4..742a3b1f 100644 --- a/test/posix-test.cc +++ b/test/posix-test.cc @@ -73,7 +73,7 @@ enum FStatSimulation { NONE, MAX_SIZE, ERROR } fstat_sim; } \ } -#ifndef _WIN32 +#ifndef _MSC_VER int test::open(const char *path, int oflag, int mode) { EMULATE_EINTR(open, -1); return ::open(path, oflag, mode); @@ -87,7 +87,17 @@ int test::fstat(int fd, struct stat *buf) { buf->st_size = max_file_size(); return result; } +#else +errno_t test::sopen_s( + int* pfh, const char *filename, int oflag, int shflag, int pmode) { + EMULATE_EINTR(open, EINTR); + return _sopen_s(pfh, filename, oflag, shflag, pmode); +} +static LONGLONG max_file_size() { return std::numeric_limits::max(); } +#endif + +#ifndef _WIN32 long test::sysconf(int name) { long result = ::sysconf(name); if (!sysconf_error) @@ -97,14 +107,6 @@ long test::sysconf(int name) { return -1; } #else -errno_t test::sopen_s( - int* pfh, const char *filename, int oflag, int shflag, int pmode) { - EMULATE_EINTR(open, EINTR); - return _sopen_s(pfh, filename, oflag, shflag, pmode); -} - -static LONGLONG max_file_size() { return std::numeric_limits::max(); } - DWORD test::GetFileSize(HANDLE hFile, LPDWORD lpFileSizeHigh) { if (fstat_sim == ERROR) { SetLastError(ERROR_ACCESS_DENIED); diff --git a/test/posix-test.h b/test/posix-test.h index 7afbbbe8..9bee85e7 100644 --- a/test/posix-test.h +++ b/test/posix-test.h @@ -31,26 +31,32 @@ #include #include -#ifndef _WIN32 -struct stat; -#else +#ifdef _WIN32 # include #endif +#ifndef _MSC_VER +struct stat; +#endif + namespace test { -#if !defined(_WIN32) || defined(__MINGW32__) +#ifndef _MSC_VER // Size type for read and write. typedef size_t size_t; typedef ssize_t ssize_t; int open(const char *path, int oflag, int mode); int fstat(int fd, struct stat *buf); -long sysconf(int name); #else typedef unsigned size_t; typedef int ssize_t; errno_t sopen_s( int* pfh, const char *filename, int oflag, int shflag, int pmode); +#endif + +#ifndef _WIN32 +long sysconf(int name); +#else DWORD GetFileSize(HANDLE hFile, LPDWORD lpFileSizeHigh); #endif