*: check defined(_WIN32) instead of defined(WIN32)
Only _WIN32 is defined by the compiler, and WIN32 is not standardized and may be missing. Closes #169
This commit is contained in:
@@ -19,7 +19,7 @@
|
||||
|
||||
#include "Clock.hxx"
|
||||
|
||||
#ifdef WIN32
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
|
||||
gcc_const
|
||||
|
@@ -22,7 +22,7 @@
|
||||
|
||||
#include "Compiler.h"
|
||||
|
||||
#ifdef WIN32
|
||||
#ifdef _WIN32
|
||||
|
||||
/**
|
||||
* Returns the uptime of the current process in seconds.
|
||||
|
@@ -47,7 +47,7 @@ FormatSystemError(std::error_code code, const char *fmt, Args&&... args)
|
||||
return std::system_error(code, buffer);
|
||||
}
|
||||
|
||||
#ifdef WIN32
|
||||
#ifdef _WIN32
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
@@ -90,7 +90,7 @@ FormatLastError(const char *fmt, Args&&... args)
|
||||
std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
#endif /* WIN32 */
|
||||
#endif /* _WIN32 */
|
||||
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
@@ -106,7 +106,7 @@ FormatLastError(const char *fmt, Args&&... args)
|
||||
static inline const std::error_category &
|
||||
ErrnoCategory()
|
||||
{
|
||||
#ifdef WIN32
|
||||
#ifdef _WIN32
|
||||
/* on Windows, the generic_category() is used for errno
|
||||
values */
|
||||
return std::generic_category();
|
||||
@@ -151,7 +151,7 @@ gcc_pure
|
||||
static inline bool
|
||||
IsFileNotFound(const std::system_error &e) noexcept
|
||||
{
|
||||
#ifdef WIN32
|
||||
#ifdef _WIN32
|
||||
return e.code().category() == std::system_category() &&
|
||||
e.code().value() == ERROR_FILE_NOT_FOUND;
|
||||
#else
|
||||
@@ -164,7 +164,7 @@ gcc_pure
|
||||
static inline bool
|
||||
IsPathNotFound(const std::system_error &e) noexcept
|
||||
{
|
||||
#ifdef WIN32
|
||||
#ifdef _WIN32
|
||||
return e.code().category() == std::system_category() &&
|
||||
e.code().value() == ERROR_PATH_NOT_FOUND;
|
||||
#else
|
||||
@@ -177,7 +177,7 @@ gcc_pure
|
||||
static inline bool
|
||||
IsAccessDenied(const std::system_error &e) noexcept
|
||||
{
|
||||
#ifdef WIN32
|
||||
#ifdef _WIN32
|
||||
return e.code().category() == std::system_category() &&
|
||||
e.code().value() == ERROR_ACCESS_DENIED;
|
||||
#else
|
||||
|
@@ -26,19 +26,19 @@
|
||||
#include <assert.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#ifdef WIN32
|
||||
#ifdef _WIN32
|
||||
#include <ws2tcpip.h>
|
||||
#include <winsock2.h>
|
||||
#include <cstring> /* for memset() */
|
||||
#endif
|
||||
|
||||
#ifdef WIN32
|
||||
#ifdef _WIN32
|
||||
static bool PoorSocketPair(int fd[2]);
|
||||
#endif
|
||||
|
||||
EventPipe::EventPipe()
|
||||
{
|
||||
#ifdef WIN32
|
||||
#ifdef _WIN32
|
||||
bool success = PoorSocketPair(fds);
|
||||
#else
|
||||
bool success = pipe_cloexec_nonblock(fds) >= 0;
|
||||
@@ -49,7 +49,7 @@ EventPipe::EventPipe()
|
||||
|
||||
EventPipe::~EventPipe()
|
||||
{
|
||||
#ifdef WIN32
|
||||
#ifdef _WIN32
|
||||
closesocket(fds[0]);
|
||||
closesocket(fds[1]);
|
||||
#else
|
||||
@@ -65,7 +65,7 @@ EventPipe::Read()
|
||||
assert(fds[1] >= 0);
|
||||
|
||||
char buffer[256];
|
||||
#ifdef WIN32
|
||||
#ifdef _WIN32
|
||||
return recv(fds[0], buffer, sizeof(buffer), 0) > 0;
|
||||
#else
|
||||
return read(fds[0], buffer, sizeof(buffer)) > 0;
|
||||
@@ -78,14 +78,14 @@ EventPipe::Write()
|
||||
assert(fds[0] >= 0);
|
||||
assert(fds[1] >= 0);
|
||||
|
||||
#ifdef WIN32
|
||||
#ifdef _WIN32
|
||||
send(fds[1], "", 1, 0);
|
||||
#else
|
||||
gcc_unused ssize_t nbytes = write(fds[1], "", 1);
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef WIN32
|
||||
#ifdef _WIN32
|
||||
|
||||
static void SafeCloseSocket(SOCKET s)
|
||||
{
|
||||
|
@@ -28,7 +28,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifdef WIN32
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#else
|
||||
#include <errno.h>
|
||||
@@ -61,7 +61,7 @@ FormatFatalError(const char *fmt, ...)
|
||||
Abort();
|
||||
}
|
||||
|
||||
#ifdef WIN32
|
||||
#ifdef _WIN32
|
||||
|
||||
void
|
||||
FatalSystemError(const char *msg, DWORD code)
|
||||
@@ -79,7 +79,7 @@ FatalSystemError(const char *msg, DWORD code)
|
||||
void
|
||||
FatalSystemError(const char *msg)
|
||||
{
|
||||
#ifdef WIN32
|
||||
#ifdef _WIN32
|
||||
FatalSystemError(msg, GetLastError());
|
||||
#else
|
||||
const char *system_error = strerror(errno);
|
||||
|
@@ -23,7 +23,7 @@
|
||||
#include "check.h"
|
||||
#include "Compiler.h"
|
||||
|
||||
#ifdef WIN32
|
||||
#ifdef _WIN32
|
||||
#include <windef.h>
|
||||
#endif
|
||||
|
||||
@@ -47,7 +47,7 @@ gcc_noreturn
|
||||
void
|
||||
FatalSystemError(const char *msg);
|
||||
|
||||
#ifdef WIN32
|
||||
#ifdef _WIN32
|
||||
|
||||
gcc_noreturn
|
||||
void
|
||||
|
@@ -33,7 +33,7 @@
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#ifndef WIN32
|
||||
#ifndef _WIN32
|
||||
#include <poll.h>
|
||||
#endif
|
||||
|
||||
@@ -70,7 +70,7 @@ FileDescriptor::OpenReadOnly(const char *pathname) noexcept
|
||||
return Open(pathname, O_RDONLY);
|
||||
}
|
||||
|
||||
#ifndef WIN32
|
||||
#ifndef _WIN32
|
||||
|
||||
bool
|
||||
FileDescriptor::OpenNonBlocking(const char *pathname) noexcept
|
||||
@@ -184,7 +184,7 @@ FileDescriptor::GetSize() const noexcept
|
||||
: -1;
|
||||
}
|
||||
|
||||
#ifndef WIN32
|
||||
#ifndef _WIN32
|
||||
|
||||
int
|
||||
FileDescriptor::Poll(short events, int timeout) const noexcept
|
||||
|
@@ -93,7 +93,7 @@ public:
|
||||
bool Open(const char *pathname, int flags, mode_t mode=0666) noexcept;
|
||||
bool OpenReadOnly(const char *pathname) noexcept;
|
||||
|
||||
#ifndef WIN32
|
||||
#ifndef _WIN32
|
||||
bool OpenNonBlocking(const char *pathname) noexcept;
|
||||
|
||||
static bool CreatePipe(FileDescriptor &r, FileDescriptor &w) noexcept;
|
||||
@@ -169,7 +169,7 @@ public:
|
||||
return ::write(fd, buffer, length);
|
||||
}
|
||||
|
||||
#ifndef WIN32
|
||||
#ifndef _WIN32
|
||||
int Poll(short events, int timeout) const noexcept;
|
||||
|
||||
int WaitReadable(int timeout) const noexcept;
|
||||
|
@@ -34,7 +34,7 @@
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
|
||||
#ifdef WIN32
|
||||
#ifdef _WIN32
|
||||
#include <ws2tcpip.h>
|
||||
#include <winsock2.h>
|
||||
#else
|
||||
@@ -45,7 +45,7 @@
|
||||
#include <sys/eventfd.h>
|
||||
#endif
|
||||
|
||||
#ifndef WIN32
|
||||
#ifndef _WIN32
|
||||
|
||||
static int
|
||||
fd_mask_flags(int fd, int and_mask, int xor_mask)
|
||||
@@ -63,12 +63,12 @@ fd_mask_flags(int fd, int and_mask, int xor_mask)
|
||||
return fcntl(fd, F_SETFD, new_flags);
|
||||
}
|
||||
|
||||
#endif /* !WIN32 */
|
||||
#endif /* !_WIN32 */
|
||||
|
||||
int
|
||||
fd_set_cloexec(int fd, bool enable)
|
||||
{
|
||||
#ifndef WIN32
|
||||
#ifndef _WIN32
|
||||
return fd_mask_flags(fd, ~FD_CLOEXEC, enable ? FD_CLOEXEC : 0);
|
||||
#else
|
||||
(void)fd;
|
||||
@@ -85,7 +85,7 @@ fd_set_cloexec(int fd, bool enable)
|
||||
static int
|
||||
fd_set_nonblock(int fd)
|
||||
{
|
||||
#ifdef WIN32
|
||||
#ifdef _WIN32
|
||||
u_long val = 1;
|
||||
return ioctlsocket(fd, FIONBIO, &val);
|
||||
#else
|
||||
@@ -124,7 +124,7 @@ open_cloexec(const char *path_fs, int flags, int mode)
|
||||
int
|
||||
pipe_cloexec_nonblock(int fd[2])
|
||||
{
|
||||
#ifdef WIN32
|
||||
#ifdef _WIN32
|
||||
return _pipe(fd, 512, _O_BINARY);
|
||||
#else
|
||||
int ret;
|
||||
@@ -199,7 +199,7 @@ accept_cloexec_nonblock(int fd, struct sockaddr *address,
|
||||
int
|
||||
close_socket(int fd)
|
||||
{
|
||||
#ifdef WIN32
|
||||
#ifdef _WIN32
|
||||
return closesocket(fd);
|
||||
#else
|
||||
return close(fd);
|
||||
|
@@ -41,7 +41,7 @@
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#ifndef WIN32
|
||||
#ifndef _WIN32
|
||||
#include <sys/types.h>
|
||||
#endif
|
||||
|
||||
|
Reference in New Issue
Block a user