Skip to content

Commit

Permalink
simplify some defines
Browse files Browse the repository at this point in the history
As far as I can tell, _WIN32 is defined for true Windows platforms.
Cygwin is a POSIX platform.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
  • Loading branch information
neheb committed Aug 8, 2022
1 parent f3b572d commit 5c90684
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 35 deletions.
4 changes: 2 additions & 2 deletions app/actions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#include <unistd.h> // for stat()
#endif

#if defined(_WIN32) || defined(__CYGWIN__)
#if defined(_WIN32)
#include <fcntl.h>
#include <io.h>
#include <sys/utime.h>
Expand Down Expand Up @@ -1669,7 +1669,7 @@ std::string temporaryPath() {
static int count = 0;
auto guard = std::scoped_lock(cs);

#if defined(_MSC_VER) || defined(__MINGW__)
#if defined(_WIN32)
HANDLE process = 0;
DWORD pid = ::GetProcessId(process);
#else
Expand Down
8 changes: 4 additions & 4 deletions app/exiv2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include <iostream>
#include <regex>

#if defined(_WIN32) || defined(__CYGWIN__)
#if defined(_WIN32)
#include <fcntl.h>
#include <io.h>
#include <windows.h>
Expand Down Expand Up @@ -942,7 +942,7 @@ static size_t readFileToBuf(FILE* f, Exiv2::DataBuf& buf) {
void Params::getStdin(Exiv2::DataBuf& buf) {
// copy stdin to stdinBuf
if (stdinBuf.empty()) {
#if defined(_WIN32) || defined(__CYGWIN__) || defined(__MINGW__) || defined(_MSC_VER)
#if defined(_WIN32)
DWORD fdwMode;
_setmode(fileno(stdin), O_BINARY);
Sleep(300);
Expand Down Expand Up @@ -1276,7 +1276,7 @@ bool parseCmdLines(ModifyCmds& modifyCmds, const Params::CmdLines& cmdLines) {
}
} // parseCmdLines

#if defined(_MSC_VER) || defined(__MINGW__)
#ifdef _WIN32
static std::string formatArg(const char* arg) {
std::string result = "";
char b = ' ';
Expand Down Expand Up @@ -1317,7 +1317,7 @@ bool parseLine(ModifyCmd& modifyCmd, const std::string& line, int num) {
std::string::size_type keyEnd = line.find_first_of(delim, keyStart + 1);
if (cmdEnd == std::string::npos || keyStart == std::string::npos) {
std::string cmdLine;
#if defined(_MSC_VER) || defined(__MINGW__)
#ifdef _WIN32
for (int i = 1; i < __argc; i++) {
cmdLine += std::string(" ") + formatArg(__argv[i]);
}
Expand Down
4 changes: 2 additions & 2 deletions include/exiv2/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
#endif

#ifndef __LITTLE_ENDIAN__
#if defined(_MSC_VER) || defined(__CYGWIN__) || defined(__MINGW__)
#if defined(_WIN32) || defined(__CYGWIN__)
#define __LITTLE_ENDIAN__ 1
#endif
#endif
Expand All @@ -62,7 +62,7 @@

///// Path separator macros /////
#ifndef EXV_SEPARATOR_STR
#if defined(_WIN32) && !defined(__CYGWIN__)
#if defined(_WIN32)
#define EXV_SEPARATOR_STR "\\"
#define EXV_SEPARATOR_CHR '\\'
#else
Expand Down
10 changes: 2 additions & 8 deletions samples/geotag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,9 @@
#include <filesystem>
#include <iostream>

#if defined(__MINGW32__) || defined(__MINGW64__)
#ifndef __MINGW__
#define __MINGW__
#endif
#endif

using namespace std;

#if defined(_MSC_VER) || defined(__MINGW__)
#ifdef _WIN32
#include <windows.h>
char* realpath(const char* file, char* path);
#define lstat _stat
Expand Down Expand Up @@ -384,7 +378,7 @@ int timeZoneAdjust() {
[[maybe_unused]] time_t now = time(nullptr);
int offset;

#if defined(_MSC_VER) || defined(__MINGW__)
#if defined(_WIN32)
TIME_ZONE_INFORMATION TimeZoneInfo;
GetTimeZoneInformation(&TimeZoneInfo);
offset = -(((int)TimeZoneInfo.Bias + (int)TimeZoneInfo.DaylightBias) * 60);
Expand Down
10 changes: 5 additions & 5 deletions src/basicio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
#include <curl/curl.h>
#endif

#if defined(__MINGW__) || defined(_MSC_VER)
#ifdef _WIN32
#define mode_t unsigned short
#include <io.h>
#include <windows.h>
Expand Down Expand Up @@ -85,7 +85,7 @@ class FileIo::Impl {
FILE* fp_{}; //!< File stream pointer
OpMode opMode_{opSeek}; //!< File open mode

#if defined _WIN32 && !defined __CYGWIN__
#if defined _WIN32
HANDLE hFile_{}; //!< Duplicated fd
HANDLE hMap_{}; //!< Handle from CreateFileMapping
#endif
Expand Down Expand Up @@ -196,7 +196,7 @@ int FileIo::munmap() {
if (::munmap(p_->pMappedArea_, p_->mappedLength_) != 0) {
rc = 1;
}
#elif defined _WIN32 && !defined __CYGWIN__
#elif defined _WIN32
UnmapViewOfFile(p_->pMappedArea_);
CloseHandle(p_->hMap_);
p_->hMap_ = 0;
Expand Down Expand Up @@ -243,7 +243,7 @@ byte* FileIo::mmap(bool isWriteable) {
}
p_->pMappedArea_ = static_cast<byte*>(rc);

#elif defined _WIN32 && !defined __CYGWIN__
#elif defined _WIN32
// Windows implementation

// TODO: An attempt to map a file with a length of 0 (zero) fails with
Expand Down Expand Up @@ -937,7 +937,7 @@ std::string XPathIo::writeDataToFile(const std::string& orgPath) {
if (prot == pStdin) {
if (isatty(fileno(stdin)))
throw Error(ErrorCode::kerInputDataReadFailed);
#if defined(_MSC_VER) || defined(__MINGW__)
#ifdef _WIN32
// convert stdin to binary
if (_setmode(_fileno(stdin), _O_BINARY) == -1)
throw Error(ErrorCode::kerInputDataReadFailed);
Expand Down
10 changes: 5 additions & 5 deletions src/convert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include <algorithm>
#include <iomanip>

#if defined _WIN32 && !defined __CYGWIN__
#if defined _WIN32
#include <windows.h>
#endif

Expand All @@ -47,7 +47,7 @@ namespace {
#if defined EXV_HAVE_ICONV
// Convert string charset with iconv.
bool convertStringCharsetIconv(std::string& str, const char* from, const char* to);
#elif defined _WIN32 && !defined __CYGWIN__
#elif defined _WIN32
// Convert string charset with Windows functions.
bool convertStringCharsetWindows(std::string& str, const char* from, const char* to);
#endif
Expand Down Expand Up @@ -1397,7 +1397,7 @@ bool convertStringCharset(std::string& str, const char* from, const char* to) {
bool ret = false;
#if defined EXV_HAVE_ICONV
ret = convertStringCharsetIconv(str, from, to);
#elif defined _WIN32 && !defined __CYGWIN__
#elif defined _WIN32
ret = convertStringCharsetWindows(str, from, to);
#else
#ifndef SUPPRESS_WARNINGS
Expand All @@ -1413,7 +1413,7 @@ bool convertStringCharset(std::string& str, const char* from, const char* to) {
namespace {
using namespace Exiv2;

#if defined _WIN32 && !defined __CYGWIN__
#if defined _WIN32
bool swapBytes(std::string& str) {
// Naive byte-swapping, I'm sure this can be done more efficiently
if (str.size() & 1) {
Expand Down Expand Up @@ -1558,7 +1558,7 @@ const ConvFctList convFctList[] = {
return ret;
}

#endif // defined _WIN32 && !defined __CYGWIN__
#endif // defined _WIN32
#if defined EXV_HAVE_ICONV
bool convertStringCharsetIconv(std::string& str, const char* from, const char* to) {
if (0 == strcmp(from, to))
Expand Down
8 changes: 4 additions & 4 deletions src/http.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include "config.h"

#if defined(_MSC_VER) || defined(__CYGWIN__) || defined(__MINGW__)
#if defined(_WIN32) || defined(__CYGWIN__)
#define __USE_W32_SOCKETS
#include <winsock2.h>
#endif
Expand All @@ -18,7 +18,7 @@
////////////////////////////////////////
// platform specific code

#if defined(__CYGWIN__) || defined(_MSC_VER) || defined(__MINGW__)
#if defined(_WIN32) || defined(__CYGWIN__)
#else
////////////////////////////////////////
// Unix or Mac
Expand Down Expand Up @@ -122,7 +122,7 @@ static Exiv2::Dictionary stringToDict(const std::string& s) {
}

static int makeNonBlocking(int sockfd) {
#ifdef _WIN32
#if defined(_WIN32) || defined(__CYGWIN__)
ULONG ioctl_opt = 1;
return ioctlsocket(sockfd, FIONBIO, &ioctl_opt);
#else
Expand All @@ -147,7 +147,7 @@ int Exiv2::http(Exiv2::Dictionary& request, Exiv2::Dictionary& response, std::st

////////////////////////////////////
// Windows specific code
#if defined(_WIN32) || defined(_MSC_VER) || defined(__MINGW__) || defined(__CYGWIN__)
#if defined(_WIN32) || defined(__CYGWIN__)
WSADATA wsaData;
WSAStartup(MAKEWORD(2, 2), &wsaData);
#endif
Expand Down
6 changes: 3 additions & 3 deletions src/makernote_int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

namespace fs = std::filesystem;

#if !defined(_MSC_VER) && !defined(__MINGW__)
#if !defined(_WIN32)
#include <pwd.h>
#include <unistd.h>
#else
Expand Down Expand Up @@ -54,7 +54,7 @@ namespace Exiv2::Internal {
// If not found in cwd, we return the default path
// which is the user profile path on win and the home dir on linux
std::string getExiv2ConfigPath() {
#if defined(_MSC_VER) || defined(__MINGW__)
#ifdef _WIN32
std::string inifile("exiv2.ini");
#else
std::string inifile(".exiv2");
Expand All @@ -65,7 +65,7 @@ std::string getExiv2ConfigPath() {
return iniPath.string();
}

#if defined(_MSC_VER) || defined(__MINGW__)
#ifdef _WIN32
char buffer[1024];
if (SUCCEEDED(SHGetFolderPathA(nullptr, CSIDL_PROFILE, nullptr, 0, buffer))) {
currentPath = buffer;
Expand Down
4 changes: 2 additions & 2 deletions src/version.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
#endif

// platform specific support for getLoadedLibraries
#if defined(__CYGWIN__) || defined(__MINGW__) || defined(_WIN32)
#if defined(_WIN32) || defined(__CYGWIN__)
// clang-format off
#include <windows.h>
#include <psapi.h>
Expand Down Expand Up @@ -119,7 +119,7 @@ static std::vector<std::string> getLoadedLibraries() {
std::set<std::string> paths;
std::string path;

#if defined(_WIN32) || defined(__CYGWIN__) || defined(__MINGW__)
#if defined(_WIN32) || defined(__CYGWIN__)
// enumerate loaded libraries and determine path to executable
HMODULE handles[200];
DWORD cbNeeded;
Expand Down

0 comments on commit 5c90684

Please sign in to comment.