Fix: [Win32] WIN32 may not be defined, always prefer the compiler predefined macro _WIN32

pull/73/head
glx 6 years ago committed by glx22
parent 8890926b0d
commit c540d72445

@ -32,9 +32,9 @@ static bool CheckAPIVersion(const char *api_version)
strcmp(api_version, "1.8") == 0 || strcmp(api_version, "1.9") == 0;
}
#if defined(WIN32)
#if defined(_WIN32)
#undef GetClassName
#endif /* WIN32 */
#endif /* _WIN32 */
template <> const char *GetClassName<AIInfo, ST_AI>() { return "AIInfo"; }
/* static */ void AIInfo::RegisterAPI(Squirrel *engine)

@ -220,7 +220,7 @@ bool HandleBootstrap()
if (BlitterFactory::GetCurrentBlitter()->GetScreenDepth() == 0) goto failure;
/* If there is no network or no freetype, then there is nothing we can do. Go straight to failure. */
#if defined(ENABLE_NETWORK) && defined(WITH_FREETYPE) && (defined(WITH_FONTCONFIG) || defined(WIN32) || defined(__APPLE__))
#if defined(ENABLE_NETWORK) && defined(WITH_FREETYPE) && (defined(WITH_FONTCONFIG) || defined(_WIN32) || defined(__APPLE__))
if (!_network_available) goto failure;
/* First tell the game we're bootstrapping. */

@ -26,7 +26,7 @@
#define TTD_BIG_ENDIAN 1
/* Windows has always LITTLE_ENDIAN */
#if defined(WIN32) || defined(__OS2__) || defined(WIN64)
#if defined(_WIN32) || defined(__OS2__)
# define TTD_ENDIAN TTD_LITTLE_ENDIAN
#elif defined(OSX)
# include <sys/types.h>
@ -42,6 +42,6 @@
# else
# define TTD_ENDIAN TTD_BIG_ENDIAN
# endif
#endif /* WIN32 || __OS2__ || WIN64 */
#endif /* _WIN32 || __OS2__ */
#endif /* ENDIAN_TYPE_HPP */

@ -17,7 +17,7 @@
#include "fileio_func.h"
#include "settings_type.h"
#if defined(WIN32) || defined(WIN64)
#if defined(_WIN32)
#include "os/windows/win32.h"
#endif
@ -139,7 +139,7 @@ static void debug_print(const char *dbg, const char *buf)
} else {
char buffer[512];
seprintf(buffer, lastof(buffer), "%sdbg: [%s] %s\n", GetLogPrefix(), dbg, buf);
#if defined(WIN32) || defined(WIN64)
#if defined(_WIN32)
TCHAR system_buf[512];
convert_to_fs(buffer, system_buf, lengthof(system_buf), true);
_fputts(system_buf, stderr);

@ -15,7 +15,7 @@
#include "fios.h"
#include "string_func.h"
#include "tar_type.h"
#ifdef WIN32
#ifdef _WIN32
#include <windows.h>
# define access _taccess
#elif defined(__HAIKU__)
@ -361,7 +361,7 @@ char *FioFindFullPath(char *buf, const char *last, Subdirectory subdir, const ch
FOR_ALL_SEARCHPATHS(sp) {
FioGetFullPath(buf, last, sp, subdir, filename);
if (FileExists(buf)) return buf;
#if !defined(WIN32)
#if !defined(_WIN32)
/* Be, as opening files, aware that sometimes the filename
* might be in uppercase when it is in lowercase on the
* disk. Of course Windows doesn't care about casing. */
@ -399,7 +399,7 @@ char *FioGetDirectory(char *buf, const char *last, Subdirectory subdir)
static FILE *FioFOpenFileSp(const char *filename, const char *mode, Searchpath sp, Subdirectory subdir, size_t *filesize)
{
#if defined(WIN32) && defined(UNICODE)
#if defined(_WIN32) && defined(UNICODE)
/* fopen is implemented as a define with ellipses for
* Unicode support (prepend an L). As we are not sending
* a string, but a variable, it 'renames' the variable,
@ -416,12 +416,12 @@ static FILE *FioFOpenFileSp(const char *filename, const char *mode, Searchpath s
seprintf(buf, lastof(buf), "%s%s%s", _searchpaths[sp], _subdirs[subdir], filename);
}
#if defined(WIN32)
#if defined(_WIN32)
if (mode[0] == 'r' && GetFileAttributes(OTTD2FS(buf)) == INVALID_FILE_ATTRIBUTES) return NULL;
#endif
f = fopen(buf, mode);
#if !defined(WIN32)
#if !defined(_WIN32)
if (f == NULL && strtolower(buf + ((subdir == NO_DIRECTORY) ? 0 : strlen(_searchpaths[sp]) - 1))) {
f = fopen(buf, mode);
}
@ -535,7 +535,7 @@ void FioCreateDirectory(const char *name)
{
/* Ignore directory creation errors; they'll surface later on, and most
* of the time they are 'directory already exists' errors anyhow. */
#if defined(WIN32)
#if defined(_WIN32)
CreateDirectory(OTTD2FS(name), NULL);
#elif defined(OS2) && !defined(__INNOTEK_LIBC__)
mkdir(OTTD2FS(name));
@ -979,14 +979,14 @@ bool ExtractTar(const char *tar_filename, Subdirectory subdir)
return true;
}
#if defined(WIN32)
#if defined(_WIN32)
/**
* Determine the base (personal dir and game data dir) paths
* @param exe the path from the current path to the executable
* @note defined in the OS related files (os2.cpp, win32.cpp, unix.cpp etc)
*/
extern void DetermineBasePaths(const char *exe);
#else /* defined(WIN32) */
#else /* defined(_WIN32) */
/**
* Changes the working directory to the path of the give executable.
@ -1149,7 +1149,7 @@ extern void cocoaSetApplicationBundleDir();
_searchpaths[SP_APPLICATION_BUNDLE_DIR] = NULL;
#endif
}
#endif /* defined(WIN32) */
#endif /* defined(_WIN32) */
const char *_personal_dir;

@ -118,7 +118,7 @@ public:
DECLARE_ENUM_AS_BIT_SET(TarScanner::Mode)
/* Implementation of opendir/readdir/closedir for Windows */
#if defined(WIN32)
#if defined(_WIN32)
struct DIR;
struct dirent { // XXX - only d_name implemented
@ -136,7 +136,7 @@ int closedir(DIR *d);
/* Use system-supplied opendir/readdir/closedir functions */
# include <sys/types.h>
# include <dirent.h>
#endif /* defined(WIN32) */
#endif /* defined(_WIN32) */
/**
* A wrapper around opendir() which will convert the string from

@ -20,9 +20,9 @@
#include "string_func.h"
#include <sys/stat.h>
#ifndef WIN32
#ifndef _WIN32
# include <unistd.h>
#endif /* WIN32 */
#endif /* _WIN32 */
#include "table/strings.h"
@ -153,7 +153,7 @@ const char *FiosBrowseTo(const FiosItem *item)
{
switch (item->type) {
case FIOS_TYPE_DRIVE:
#if defined(WIN32) || defined(__OS2__)
#if defined(_WIN32) || defined(__OS2__)
seprintf(_fios_path, _fios_path_last, "%c:" PATHSEP, item->title[0]);
#endif
break;
@ -318,7 +318,7 @@ bool FiosFileScanner::AddFile(const char *filename, size_t basepath_length, cons
}
FiosItem *fios = file_list.Append();
#ifdef WIN32
#ifdef _WIN32
struct _stat sb;
if (_tstat(OTTD2FS(filename), &sb) == 0) {
#else

@ -28,7 +28,7 @@ extern FT_Library _library;
* Windows support
* ======================================================================================== */
#ifdef WIN32
#ifdef _WIN32
#include "core/alloc_func.hpp"
#include "core/math_func.hpp"
#include <windows.h>

@ -29,9 +29,9 @@ static bool CheckAPIVersion(const char *api_version)
strcmp(api_version, "1.8") == 0 || strcmp(api_version, "1.9") == 0;
}
#if defined(WIN32)
#if defined(_WIN32)
#undef GetClassName
#endif /* WIN32 */
#endif /* _WIN32 */
template <> const char *GetClassName<GameInfo, ST_GS>() { return "GSInfo"; }
/* static */ void GameInfo::RegisterAPI(Squirrel *engine)

@ -19,7 +19,7 @@
# include <unistd.h>
#endif
#ifdef WIN32
#ifdef _WIN32
# include <windows.h>
# include <shellapi.h>
# include "core/mem_func.hpp"
@ -87,7 +87,7 @@ bool IniFile::SaveToDisk(const char *filename)
fclose(f);
#endif
#if defined(WIN32) || defined(WIN64)
#if defined(_WIN32)
/* _tcsncpy = strcpy is TCHAR is char, but isn't when TCHAR is wchar. */
#undef strncpy
/* Allocate space for one more \0 character. */

@ -64,7 +64,7 @@ bool NetworkCoreInitialize()
#endif /* __MORPHOS__ / __AMIGA__ */
/* Let's load the network in windows */
#ifdef WIN32
#ifdef _WIN32
{
WSADATA wsa;
DEBUG(net, 3, "[core] loading windows socket library");
@ -73,7 +73,7 @@ bool NetworkCoreInitialize()
return false;
}
}
#endif /* WIN32 */
#endif /* _WIN32 */
return true;
}
@ -94,7 +94,7 @@ void NetworkCoreShutdown()
if (SocketBase != NULL) CloseLibrary(SocketBase);
#endif
#if defined(WIN32)
#if defined(_WIN32)
WSACleanup();
#endif
}

@ -107,7 +107,7 @@ static void NetworkFindBroadcastIPsInternal(NetworkAddressList *broadcast) // GE
freeifaddrs(ifap);
}
#elif defined(WIN32)
#elif defined(_WIN32)
static void NetworkFindBroadcastIPsInternal(NetworkAddressList *broadcast) // Win32 implementation
{
SOCKET sock = socket(AF_INET, SOCK_DGRAM, 0);

@ -21,7 +21,7 @@
#ifdef ENABLE_NETWORK
/* Windows stuff */
#if defined(WIN32) || defined(WIN64)
#if defined(_WIN32)
#include <errno.h>
#include <winsock2.h>
#include <ws2tcpip.h>
@ -125,7 +125,7 @@ static inline void OTTDfreeaddrinfo(struct addrinfo *ai)
}
#define freeaddrinfo OTTDfreeaddrinfo
#endif /* __MINGW32__ && __CYGWIN__ */
#endif /* WIN32 */
#endif /* _WIN32 */
/* UNIX stuff */
#if defined(UNIX) && !defined(__OS2__)
@ -290,7 +290,7 @@ typedef unsigned long in_addr_t;
*/
static inline bool SetNonBlocking(SOCKET d)
{
#ifdef WIN32
#ifdef _WIN32
u_long nonblocking = 1;
#else
int nonblocking = 1;

@ -168,7 +168,7 @@ static void ShowHelp()
" -P password = Password to join company\n"
" -D [ip][:port] = Start dedicated server\n"
" -l ip[:port] = Redirect DEBUG()\n"
#if !defined(__MORPHOS__) && !defined(__AMIGA__) && !defined(WIN32)
#if !defined(__MORPHOS__) && !defined(__AMIGA__) && !defined(_WIN32)
" -f = Fork into the background (dedicated only)\n"
#endif
#endif /* ENABLE_NETWORK */
@ -212,7 +212,7 @@ static void ShowHelp()
/* ShowInfo put output to stderr, but version information should go
* to stdout; this is the only exception */
#if !defined(WIN32) && !defined(WIN64)
#if !defined(_WIN32)
printf("%s\n", buf);
#else
ShowInfo(buf);
@ -250,7 +250,7 @@ static void WriteSavegameInfo(const char *name)
/* ShowInfo put output to stderr, but version information should go
* to stdout; this is the only exception */
#if !defined(WIN32) && !defined(WIN64)
#if !defined(_WIN32)
printf("%s\n", buf);
#else
ShowInfo(buf);
@ -514,7 +514,7 @@ static const OptionData _options[] = {
GETOPT_SHORT_VALUE('l'),
GETOPT_SHORT_VALUE('p'),
GETOPT_SHORT_VALUE('P'),
#if !defined(__MORPHOS__) && !defined(__AMIGA__) && !defined(WIN32)
#if !defined(__MORPHOS__) && !defined(__AMIGA__) && !defined(_WIN32)
GETOPT_SHORT_NOVAL('f'),
#endif
#endif /* ENABLE_NETWORK */
@ -614,7 +614,7 @@ int openttd_main(int argc, char *argv[])
case 'r': ParseResolution(&resolution, mgo.opt); break;
case 't': scanner->startyear = atoi(mgo.opt); break;
case 'd': {
#if defined(WIN32)
#if defined(_WIN32)
CreateConsole();
#endif
if (mgo.opt != NULL) SetDebugString(mgo.opt);

@ -134,7 +134,7 @@ void ScriptScanner::RegisterScript(ScriptInfo *info)
if (this->info_list.find(script_name) != this->info_list.end()) {
/* This script was already registered */
#ifdef WIN32
#ifdef _WIN32
/* Windows doesn't care about the case */
if (strcasecmp(this->info_list[script_name]->GetMainScript(), info->GetMainScript()) == 0) {
#else

@ -15,7 +15,7 @@
const char *SdlOpen(uint32 x);
void SdlClose(uint32 x);
#ifdef WIN32
#ifdef _WIN32
#define DYNAMICALLY_LOADED_SDL
#endif

@ -1668,9 +1668,9 @@ static void HandleSettingDescs(IniFile *ini, SettingDescProc *proc, SettingDescP
{
if (basic_settings) {
proc(ini, (const SettingDesc*)_misc_settings, "misc", NULL);
#if defined(WIN32) && !defined(DEDICATED)
#if defined(_WIN32) && !defined(DEDICATED)
proc(ini, (const SettingDesc*)_win32_settings, "win32", NULL);
#endif /* WIN32 */
#endif /* _WIN32 */
}
if (other_settings) {

@ -18,7 +18,7 @@
#include <stdarg.h>
#if (!defined(WIN32) && !defined(WIN64)) || defined(__CYGWIN__)
#if !defined(_WIN32) || defined(__CYGWIN__)
#include <unistd.h>
#include <sys/stat.h>
#endif
@ -512,7 +512,7 @@ int CDECL main(int argc, char *argv[])
unlink(tmp_output);
} else {
/* Rename tmp2.xxx to output file. */
#if defined(WIN32) || defined(WIN64)
#if defined(_WIN32)
unlink(output_file);
#endif
if (rename(tmp_output, output_file) == -1) error("rename() failed");

@ -167,7 +167,7 @@
#include <malloc.h> // alloca()
#endif
#if defined(WIN32)
#if defined(_WIN32)
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
#endif
@ -232,18 +232,18 @@
#define FALLTHROUGH
#endif
#if defined(WIN32) && !defined(_WIN64) && !defined(WIN64)
# if defined(_WIN32) && !defined(_WIN64)
#if !defined(_W64)
#define _W64
#endif
typedef _W64 int INT_PTR, *PINT_PTR;
typedef _W64 unsigned int UINT_PTR, *PUINT_PTR;
#endif /* WIN32 && !_WIN64 && !WIN64 */
# endif /* _WIN32 && !_WIN64 */
#if defined(_WIN64) || defined(WIN64)
# if defined(_WIN64)
#define fseek _fseeki64
#endif /* _WIN64 || WIN64 */
# endif /* _WIN64 */
/* zlib from vcpkg use cdecl calling convention without enforcing it in the headers */
# if defined(WITH_ZLIB)
@ -281,7 +281,7 @@
/* NOTE: the string returned by these functions is only valid until the next
* call to the same function and is not thread- or reentrancy-safe */
#if !defined(STRGEN) && !defined(SETTINGSGEN)
#if defined(WIN32) || defined(WIN64)
# if defined(_WIN32)
char *getcwd(char *buf, size_t size);
#include <tchar.h>
#include <io.h>
@ -292,14 +292,14 @@
const char *FS2OTTD(const TCHAR *name);
const TCHAR *OTTD2FS(const char *name, bool console_cp = false);
#else
# else
#define fopen(file, mode) fopen(OTTD2FS(file), mode)
const char *FS2OTTD(const char *name);
const char *OTTD2FS(const char *name);
#endif /* WIN32 */
# endif /* _WIN32 */
#endif /* STRGEN || SETTINGSGEN */
#if defined(WIN32) || defined(WIN64) || defined(__OS2__) && !defined(__INNOTEK_LIBC__)
#if defined(_WIN32) || defined(__OS2__) && !defined(__INNOTEK_LIBC__)
#define PATHSEP "\\"
#define PATHSEPCHAR '\\'
#else

@ -21,14 +21,14 @@
#include <stdarg.h>
#include <exception>
#if (!defined(WIN32) && !defined(WIN64)) || defined(__CYGWIN__)
#if !defined(_WIN32) || defined(__CYGWIN__)
#include <unistd.h>
#include <sys/stat.h>
#endif
#if defined WIN32 || defined __WATCOMC__
#if defined(_WIN32) || defined(__WATCOMC__)
#include <direct.h>
#endif /* WIN32 || __WATCOMC__ */
#endif /* _WIN32 || __WATCOMC__ */
#ifdef __MORPHOS__
#ifdef stderr
@ -333,9 +333,9 @@ struct HeaderFileWriter : HeaderWriter, FileWriter {
unlink(this->filename);
} else {
/* else rename tmp.xxx into filename */
#if defined(WIN32) || defined(WIN64)
# if defined(_WIN32)
unlink(this->real_filename);
#endif
# endif
if (rename(this->filename, this->real_filename) == -1) error("rename() failed");
}
}
@ -377,7 +377,7 @@ static inline void ottd_mkdir(const char *directory)
{
/* Ignore directory creation errors; they'll surface later on, and most
* of the time they are 'directory already exists' errors anyhow. */
#if defined(WIN32) || defined(__WATCOMC__)
#if defined(_WIN32) || defined(__WATCOMC__)
mkdir(directory);
#else
mkdir(directory, 0755);

@ -25,7 +25,7 @@
#include <errno.h> // required by vsnprintf implementation for MSVC
#endif
#ifdef WIN32
#ifdef _WIN32
#include "os/windows/win32.h"
#endif
@ -359,7 +359,7 @@ bool IsValidChar(WChar key, CharSetFilter afilter)
}
}
#ifdef WIN32
#ifdef _WIN32
#if defined(_MSC_VER) && _MSC_VER < 1900
/**
* Almost POSIX compliant implementation of \c vsnprintf for VC compiler.
@ -395,7 +395,7 @@ int CDECL vsnprintf(char *str, size_t size, const char *format, va_list ap)
}
#endif /* _MSC_VER */
#endif /* WIN32 */
#endif /* _WIN32 */
/**
* Safer implementation of snprintf; same as snprintf except:
@ -592,7 +592,7 @@ int strnatcmp(const char *s1, const char *s2, bool ignore_garbage_at_front)
}
#endif /* WITH_ICU_SORT */
#if defined(WIN32) && !defined(STRGEN) && !defined(SETTINGSGEN)
#if defined(_WIN32) && !defined(STRGEN) && !defined(SETTINGSGEN)
int res = OTTDStringCompare(s1, s2);
if (res != 0) return res - 2; // Convert to normal C return values.
#endif

@ -1786,7 +1786,7 @@ bool ReadLanguagePack(const LanguageMetadata *lang)
strecpy(_config_language_file, c_file, lastof(_config_language_file));
SetCurrentGrfLangID(_current_language->newgrflangid);
#ifdef WIN32
#ifdef _WIN32
extern void Win32SetCurrentLocaleName(const char *iso_code);
Win32SetCurrentLocaleName(_current_language->isocode);
#endif
@ -1837,7 +1837,7 @@ bool ReadLanguagePack(const LanguageMetadata *lang)
/* Win32 implementation in win32.cpp.
* OS X implementation in os/macosx/macos.mm. */
#if !(defined(WIN32) || defined(__APPLE__))
#if !(defined(_WIN32) || defined(__APPLE__))
/**
* Determine the current charset based on the environment
* First check some default values, after this one we passed ourselves
@ -1865,7 +1865,7 @@ const char *GetCurrentLocale(const char *param)
}
#else
const char *GetCurrentLocale(const char *param);
#endif /* !(defined(WIN32) || defined(__APPLE__)) */
#endif /* !(defined(_WIN32) || defined(__APPLE__)) */
int CDECL StringIDSorter(const StringID *a, const StringID *b)
{

@ -8,14 +8,14 @@
[pre-amble]
/* win32_v.cpp only settings */
#if defined(WIN32) && !defined(DEDICATED)
#if defined(_WIN32) && !defined(DEDICATED)
extern bool _force_full_redraw, _window_maximize;
extern uint _display_hz;
static const SettingDescGlobVarList _win32_settings[] = {
[post-amble]
};
#endif /* WIN32 */
#endif /* _WIN32 */
[templates]
SDTG_BOOL = SDTG_BOOL($name, $flags, $guiflags, $var, $def, $str, $strhelp, $strval, $proc, $from, $to, $cat),
SDTG_VAR = SDTG_VAR($name, $type, $flags, $guiflags, $var, $def, $min, $max, $interval, $str, $strhelp, $strval, $proc, $from, $to, $cat),

@ -73,7 +73,7 @@ static void DedicatedSignalHandler(int sig)
}
#endif
#if defined(WIN32)
#if defined(_WIN32)
# include <windows.h> /* GetTickCount */
# include <conio.h>
# include <time.h>
@ -150,7 +150,7 @@ const char *VideoDriver_Dedicated::Start(const char * const *parm)
ScreenSizeChanged();
BlitterFactory::GetCurrentBlitter()->PostResize();
#if defined(WIN32)
#if defined(_WIN32)
/* For win32 we need to allocate a console (debug mode does the same) */
CreateConsole();
CreateWindowsConsoleThread();
@ -173,7 +173,7 @@ const char *VideoDriver_Dedicated::Start(const char * const *parm)
void VideoDriver_Dedicated::Stop()
{
#ifdef WIN32
#ifdef _WIN32
CloseWindowsConsoleThread();
#endif
free(_dedicated_video_mem);

@ -264,7 +264,7 @@ static void GetAvailableVideoMode(uint *w, uint *h)
*h = _resolutions[best].height;
}
#ifdef WIN32
#ifdef _WIN32
/* Let's redefine the LoadBMP macro with because we are dynamically
* loading SDL and need to 'SDL_CALL' all functions */
#undef SDL_LoadBMP
@ -500,7 +500,7 @@ static uint ConvertSdlKeyIntoMy(SDL_keysym *sym, WChar *character)
}
/* check scancode for BACKQUOTE key, because we want the key left of "1", not anything else (on non-US keyboards) */
#if defined(WIN32) || defined(__OS2__)
#if defined(_WIN32) || defined(__OS2__)
if (sym->scancode == 41) key = WKC_BACKQUOTE;
#elif defined(__APPLE__)
if (sym->scancode == 10) key = WKC_BACKQUOTE;

Loading…
Cancel
Save