Rewrote usages of define(_MSC_VER) to ifdef _MSC_VER

This commit is contained in:
Tomer Lev 2022-11-01 19:52:22 +02:00
parent 5cdc6e150e
commit a105ea9d80
6 changed files with 17 additions and 19 deletions

View file

@ -8,7 +8,7 @@
#include "zeek/Reporter.h" #include "zeek/Reporter.h"
#if defined(_MSC_VER) #ifdef _MSC_VER
#include <winsock2.h> #include <winsock2.h>
@ -31,10 +31,8 @@ namespace zeek::detail
{ {
Flare::Flare() Flare::Flare()
#if ! defined(_MSC_VER) #ifndef _MSC_VER
: pipe(FD_CLOEXEC, FD_CLOEXEC, O_NONBLOCK, O_NONBLOCK) : pipe(FD_CLOEXEC, FD_CLOEXEC, O_NONBLOCK, O_NONBLOCK){}
{
}
#else #else
{ {
WSADATA wsaData; WSADATA wsaData;
@ -64,7 +62,7 @@ Flare::Flare()
} }
#endif #endif
[[noreturn]] static void bad_pipe_op(const char* which, bool signal_safe) [[noreturn]] static void bad_pipe_op(const char* which, bool signal_safe)
{ {
if ( signal_safe ) if ( signal_safe )
abort(); abort();
@ -87,7 +85,7 @@ void Flare::Fire(bool signal_safe)
for ( ;; ) for ( ;; )
{ {
#if ! defined(_MSC_VER) #ifndef _MSC_VER
int n = write(pipe.WriteFD(), &tmp, 1); int n = write(pipe.WriteFD(), &tmp, 1);
#else #else
@ -99,7 +97,7 @@ void Flare::Fire(bool signal_safe)
if ( n < 0 ) if ( n < 0 )
{ {
#if defined(_MSC_VER) #ifdef _MSC_VER
errno = WSAGetLastError(); errno = WSAGetLastError();
bad_pipe_op("send", signal_safe); bad_pipe_op("send", signal_safe);
#endif #endif
@ -125,7 +123,7 @@ int Flare::Extinguish(bool signal_safe)
for ( ;; ) for ( ;; )
{ {
#if ! defined(_MSC_VER) #ifndef _MSC_VER
int n = read(pipe.ReadFD(), &tmp, sizeof(tmp)); int n = read(pipe.ReadFD(), &tmp, sizeof(tmp));
#else #else
int n = recv(recvfd, tmp, sizeof(tmp), 0); int n = recv(recvfd, tmp, sizeof(tmp), 0);
@ -136,7 +134,7 @@ int Flare::Extinguish(bool signal_safe)
// Pipe may not be empty yet: try again. // Pipe may not be empty yet: try again.
continue; continue;
} }
#if defined(_MSC_VER) #ifdef _MSC_VER
if ( WSAGetLastError() == WSAEWOULDBLOCK ) if ( WSAGetLastError() == WSAEWOULDBLOCK )
break; break;
errno = WSAGetLastError(); errno = WSAGetLastError();

View file

@ -2,7 +2,7 @@
#pragma once #pragma once
#if ! defined(_MSC_VER) #ifndef _MSC_VER
#include "Pipe.h" #include "Pipe.h"
#endif #endif
@ -25,7 +25,7 @@ public:
* Fire()'d and not yet Extinguished()'d. * Fire()'d and not yet Extinguished()'d.
*/ */
int FD() const int FD() const
#if ! defined(_MSC_VER) #ifndef _MSC_VER
{ {
return pipe.ReadFD(); return pipe.ReadFD();
} }
@ -52,7 +52,7 @@ public:
int Extinguish(bool signal_safe = false); int Extinguish(bool signal_safe = false);
private: private:
#if ! defined(_MSC_VER) #ifndef _MSC_VER
Pipe pipe; Pipe pipe;
#else #else
int sendfd, recvfd; int sendfd, recvfd;

View file

@ -9,13 +9,13 @@
#include "zeek/supervisor/Supervisor.h" #include "zeek/supervisor/Supervisor.h"
#include "zeek/zeek-setup.h" #include "zeek/zeek-setup.h"
#if defined(_MSC_VER) #ifdef _MSC_VER
#include <fcntl.h> // For _O_BINARY. #include <fcntl.h> // For _O_BINARY.
#endif #endif
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
#if defined(_MSC_VER) #ifdef _MSC_VER
_setmode(_fileno(stdout), _O_BINARY); _setmode(_fileno(stdout), _O_BINARY);
_setmode(_fileno(stderr), _O_BINARY); _setmode(_fileno(stderr), _O_BINARY);
#endif #endif

View file

@ -3,7 +3,7 @@
#include "zeek/plugin/Manager.h" #include "zeek/plugin/Manager.h"
#include <dirent.h> #include <dirent.h>
#if ! defined(_MSC_VER) #ifndef _MSC_VER
#include <dlfcn.h> #include <dlfcn.h>
#include <glob.h> #include <glob.h>
#endif #endif
@ -163,7 +163,7 @@ bool Manager::ActivateDynamicPluginInternal(const std::string& name, bool ok_if_
std::vector<std::string>* errors) std::vector<std::string>* errors)
{ {
// Loading dynamic plugins is not currently supported on Windows platform. // Loading dynamic plugins is not currently supported on Windows platform.
#if defined(_MSC_VER) #ifdef _MSC_VER
return false; return false;
#else #else
errors->clear(); // caller should pass it in empty, but just to be sure errors->clear(); // caller should pass it in empty, but just to be sure

View file

@ -25,7 +25,7 @@ struct Field;
namespace zeek namespace zeek
{ {
#if defined(_MSC_VER) #ifdef _MSC_VER
#undef VOID #undef VOID
#endif #endif

View file

@ -2539,7 +2539,7 @@ static void strerror_r_helper(int result, char* buf, size_t buflen)
void zeek_strerror_r(int zeek_errno, char* buf, size_t buflen) void zeek_strerror_r(int zeek_errno, char* buf, size_t buflen)
{ {
#if defined(_MSC_VER) #ifdef _MSC_VER
auto str = "Error number: " + std::to_string(zeek_errno); auto str = "Error number: " + std::to_string(zeek_errno);
auto res = str.data(); auto res = str.data();
#else #else