What changed, and why it matters
This commit is a code cleanup that replaces the non-standard WIN32 preprocessor macro with the compiler-defined _WIN32 macro across 18 files. It does not change program logic or behavior; it only makes Windows-specific code detection more reliable and portable. There is no direct security vulnerability being fixed here, though using the compiler-defined macro reduces the risk of build misconfiguration on Windows.
No immediate security action required. Treat as a normal build/portability improvement. Ensure downstream build systems do not rely on the WIN32 macro being defined, as the project now expects _WIN32.
Security signals we found
No functional code changes observed
Preprocessor macro standardization only
Windows-specific code paths remain identical in behavior
No memory safety, cryptographic, or input validation changes
No references to CVEs, advisories, or security issues in commit metadata
Evidence from the diff
The patch uniformly changes conditional compilation directives from #ifdef/#ifndef defined(WIN32) to defined(_WIN32). _WIN32 is the macro defined by Microsoft Visual C++ and compatible Windows compilers, whereas WIN32 is a user/project-defined macro that may not be set consistently. The change affects Windows-specific code paths for console handling, logging, file locking, password input, daemonization, wallet file I/O, and locale setup. No functional code changes are introduced.
Changed components
Windows build configurationConsole handling (contrib/epee)Logging (contrib/epee/mlog)Blockchain LMDB databasePassword inputFile locking and utility functionsDaemon service wrapperSimplewalletWallet API and wallet2Inspect captured patch +52 / −52
### contrib/epee/include/console_handler.h
@@ -112,7 +112,7 @@ namespace epee
// Both the console and the signal thread may call this.
if (m_run.exchange(false))
{
-#if defined(WIN32)
+#if defined(_WIN32)
::CloseHandle(::GetStdHandle(STD_INPUT_HANDLE));
#endif
@@ -165,7 +165,7 @@ namespace epee
bool wait_stdin_data()
{
-#if !defined(WIN32)
+#if !defined(_WIN32)
#if defined(__OpenBSD__) || defined(__ANDROID__)
int stdin_fileno = fileno(stdin);
#else
### contrib/epee/src/mlog.cpp
@@ -120,7 +120,7 @@ static const char *get_default_categories(int level)
return categories;
}
-#ifdef WIN32
+#ifdef _WIN32
bool EnableVTMode()
{
// Set output mode to handle virtual terminal sequences
@@ -231,7 +231,7 @@ void mlog_configure(const std::string &filename_base, bool console, const std::s
monero_log = get_default_categories(0);
}
mlog_set_log(monero_log);
-#ifdef WIN32
+#ifdef _WIN32
EnableVTMode();
#endif
}
@@ -350,7 +350,7 @@ bool is_stdout_a_tty()
if (!initialized.load(std::memory_order_acquire))
{
-#if defined(WIN32)
+#if defined(_WIN32)
is_a_tty.store(0 != _isatty(_fileno(stdout)), std::memory_order_relaxed);
#else
is_a_tty.store(0 != isatty(fileno(stdout)), std::memory_order_relaxed);
@@ -380,7 +380,7 @@ void set_console_color(int color, bool bright)
{
case console_color_default:
{
-#ifdef WIN32
+#ifdef _WIN32
HANDLE h_stdout = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(h_stdout, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE| (bright ? FOREGROUND_INTENSITY:0));
#else
@@ -393,7 +393,7 @@ void set_console_color(int color, bool bright)
break;
case console_color_white:
{
-#ifdef WIN32
+#ifdef _WIN32
HANDLE h_stdout = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(h_stdout, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE | (bright ? FOREGROUND_INTENSITY:0));
#else
@@ -406,7 +406,7 @@ void set_console_color(int color, bool bright)
break;
case console_color_red:
{
-#ifdef WIN32
+#ifdef _WIN32
HANDLE h_stdout = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(h_stdout, FOREGROUND_RED | (bright ? FOREGROUND_INTENSITY:0));
#else
@@ -419,7 +419,7 @@ void set_console_color(int color, bool bright)
break;
case console_color_green:
{
-#ifdef WIN32
+#ifdef _WIN32
HANDLE h_stdout = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(h_stdout, FOREGROUND_GREEN | (bright ? FOREGROUND_INTENSITY:0));
#else
@@ -433,7 +433,7 @@ void set_console_color(int color, bool bright)
case console_color_blue:
{
-#ifdef WIN32
+#ifdef _WIN32
HANDLE h_stdout = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(h_stdout, FOREGROUND_BLUE | FOREGROUND_INTENSITY);//(bright ? FOREGROUND_INTENSITY:0));
#else
@@ -447,7 +447,7 @@ void set_console_color(int color, bool bright)
case console_color_cyan:
{
-#ifdef WIN32
+#ifdef _WIN32
HANDLE h_stdout = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(h_stdout, FOREGROUND_GREEN | FOREGROUND_BLUE | (bright ? FOREGROUND_INTENSITY:0));
#else
@@ -461,7 +461,7 @@ void set_console_color(int color, bool bright)
case console_color_magenta:
{
-#ifdef WIN32
+#ifdef _WIN32
HANDLE h_stdout = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(h_stdout, FOREGROUND_BLUE | FOREGROUND_RED | (bright ? FOREGROUND_INTENSITY:0));
#else
@@ -475,7 +475,7 @@ void set_console_color(int color, bool bright)
case console_color_yellow:
{
-#ifdef WIN32
+#ifdef _WIN32
HANDLE h_stdout = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(h_stdout, FOREGROUND_RED | FOREGROUND_GREEN | (bright ? FOREGROUND_INTENSITY:0));
#else
@@ -497,7 +497,7 @@ void reset_console_color() {
if (is_nocolor())
return;
-#ifdef WIN32
+#ifdef _WIN32
HANDLE h_stdout = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(h_stdout, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
#else
### src/blockchain_db/lmdb/db_lmdb.cpp
@@ -35,7 +35,7 @@
#include <memory> // std::unique_ptr
#include <cstring> // memcpy
-#ifdef WIN32
+#ifdef _WIN32
#include <winioctl.h>
#endif
@@ -2124,7 +2124,7 @@ BlockchainLMDB::BlockchainLMDB(bool batch_transactions, std::shared_ptr<fcmp_pp:
m_curve_trees = curve_trees;
}
-#ifdef WIN32
+#ifdef _WIN32
static bool disable_ntfs_compression(const boost::filesystem::path& filepath)
{
DWORD file_attributes = ::GetFileAttributesW(filepath.c_str());
@@ -2198,7 +2198,7 @@ void BlockchainLMDB::open(const std::string& filename, const int db_flags)
throw DB_ERROR("Database could not be opened");
}
-#ifdef WIN32
+#ifdef _WIN32
// ensure NTFS compression is disabled on the directory and database file to avoid corruption of the blockchain
if (!disable_ntfs_compression(filename))
LOG_PRINT_L0("Failed to disable NTFS compression on folder: " << filename << ". Error: " << ::GetLastError());
### src/common/password.cpp
@@ -109,7 +109,7 @@ namespace
return r;
}
-#else // end WIN32
+#else // if not _WIN32
bool is_cin_tty() noexcept
{
@@ -173,7 +173,7 @@ namespace
return true;
}
-#endif // end !WIN32
+#endif // not _WIN32
bool read_from_tty(const bool verify, const char *message, bool hide_input, epee::wipeable_string& pass1, epee::wipeable_string& pass2)
{
### src/common/util.cpp
@@ -63,7 +63,7 @@ using namespace epee;
#include "memwipe.h"
#include "net/http_client.h" // epee::net_utils::...
-#ifdef WIN32
+#ifdef _WIN32
#include <windows.h>
#include <shlobj.h>
#else
@@ -133,7 +133,7 @@ namespace tools
private_file private_file::create(std::string name, uint32_t extra_flags)
{
-#ifdef WIN32
+#ifdef _WIN32
struct close_handle
{
void operator()(HANDLE handle) const noexcept
@@ -244,7 +244,7 @@ namespace tools
return {};
}
}
-#ifdef WIN32
+#ifdef _WIN32
return create(filename);
#else
return create(filename, O_EXCL);
@@ -263,7 +263,7 @@ namespace tools
file_locker::file_locker(const std::string &filename)
{
-#ifdef WIN32
+#ifdef _WIN32
m_fd = INVALID_HANDLE_VALUE;
std::wstring filename_wide;
try
@@ -312,7 +312,7 @@ namespace tools
{
if (locked())
{
-#ifdef WIN32
+#ifdef _WIN32
CloseHandle(m_fd);
#else
close(m_fd);
@@ -321,15 +321,15 @@ namespace tools
}
bool file_locker::locked() const
{
-#ifdef WIN32
+#ifdef _WIN32
return m_fd != INVALID_HANDLE_VALUE;
#else
return m_fd != -1;
#endif
}
-#ifdef WIN32
+#ifdef _WIN32
std::string get_special_folder_path(int nfolder, bool iscreate)
{
WCHAR psz_path[MAX_PATH] = L"";
@@ -362,7 +362,7 @@ namespace tools
// Unix & Mac: ~/.CRYPTONOTE_NAME
std::string config_folder;
-#ifdef WIN32
+#ifdef _WIN32
config_folder = get_special_folder_path(CSIDL_COMMON_APPDATA, true) + "\\" + CRYPTONOTE_NAME;
#else
std::string pathRet;
@@ -403,7 +403,7 @@ namespace tools
std::error_code replace_file(const std::string& old_name, const std::string& new_name)
{
int code;
-#if defined(WIN32)
+#if defined(_WIN32)
// Maximizing chances for success
std::wstring wide_replacement_name;
try { wide_replacement_name = string_tools::utf8_to_utf16(old_name); }
### src/common/util.h
@@ -105,7 +105,7 @@ namespace tools
~file_locker();
bool locked() const;
private:
-#ifdef WIN32
+#ifdef _WIN32
HANDLE m_fd;
#else
int m_fd;
@@ -124,7 +124,7 @@ namespace tools
*/
std::string get_default_data_dir();
-#ifdef WIN32
+#ifdef _WIN32
/**
* @brief
*
@@ -161,7 +161,7 @@ namespace tools
template<typename T>
static bool install(T t)
{
-#if defined(WIN32)
+#if defined(_WIN32)
bool r = TRUE == ::SetConsoleCtrlHandler(&win_handler, TRUE);
if (r)
{
@@ -183,7 +183,7 @@ namespace tools
}
private:
-#if defined(WIN32)
+#if defined(_WIN32)
/*! \brief Handler for win */
static BOOL WINAPI win_handler(DWORD type)
{
### src/crypto/oaes_lib.c
@@ -47,7 +47,7 @@
#include <sys/time.h>
#endif
-#ifdef WIN32
+#ifdef _WIN32
#include <process.h>
#else
#include <sys/types.h>
### src/crypto/oaes_lib.h
@@ -50,7 +50,7 @@ extern "C" {
# endif
#else
# define OAES_API
-#endif // WIN32
+#endif // _WIN32
#define OAES_VERSION "0.8.1"
#define OAES_BLOCK_SIZE 16
### src/daemon/main.cpp
@@ -125,7 +125,7 @@ bf::path get_config_file_path(const po::variables_map &vm)
return config_path;
}
-#ifdef WIN32
+#ifdef _WIN32
bool isFat32(const wchar_t* root_path)
{
std::vector<wchar_t> fs(MAX_PATH + 1);
@@ -273,7 +273,7 @@ int main(int argc, char const * argv[])
boost::filesystem::path data_dir = boost::filesystem::absolute(
command_line::get_arg(vm, cryptonote::arg_data_dir));
-#ifdef WIN32
+#ifdef _WIN32
if (isFat32(data_dir.root_path().c_str()))
{
MERROR("Data directory resides on FAT32 volume that has 4GiB file size limit, blockchain might get corrupted.");
### src/daemon/rpc_command_executor.cpp
@@ -1420,7 +1420,7 @@ bool t_rpc_command_executor::stop_daemon()
cryptonote::COMMAND_RPC_STOP_DAEMON::request req;
cryptonote::COMMAND_RPC_STOP_DAEMON::response res;
-//# ifdef WIN32
+//# ifdef _WIN32
// // Stop via service API
// // TODO - this is only temporary! Get rid of hard-coded constants!
// bool ok = windows::stop_service("BitMonero Daemon");
### src/daemonizer/daemonizer.h
@@ -66,7 +66,7 @@ namespace daemonizer
};
}
-#ifdef WIN32
+#ifdef _WIN32
# include "daemonizer/windows_daemonizer.inl"
#else
# include "daemonizer/posix_daemonizer.inl"
### src/daemonizer/posix_fork.h
@@ -29,7 +29,7 @@
#pragma once
#include <string>
-#ifndef WIN32
+#ifndef _WIN32
namespace posix {
### src/daemonizer/windows_service.h
@@ -28,7 +28,7 @@
#pragma once
-#ifdef WIN32
+#ifdef _WIN32
#undef UNICODE
#undef _UNICODE
### src/daemonizer/windows_service_runner.h
@@ -28,7 +28,7 @@
#pragma once
-#ifdef WIN32
+#ifdef _WIN32
#undef UNICODE
#undef _UNICODE
### src/simplewallet/simplewallet.cpp
@@ -72,7 +72,7 @@
#include "QrCode.hpp"
#include "net/parse.h"
-#ifdef WIN32
+#ifdef _WIN32
#include <boost/locale.hpp>
#include <fcntl.h>
#include <io.h>
@@ -806,7 +806,7 @@ namespace
fflush(stdout);
while (size > 0)
{
-#ifdef WIN32
+#ifdef _WIN32
const int n = _write(_fileno(stdout), data, size > INT_MAX ? INT_MAX : (unsigned int)size);
#else
const ssize_t n = ::write(STDOUT_FILENO, data, size);
@@ -10707,7 +10707,7 @@ int main(int argc, char* argv[])
{
TRY_ENTRY();
-#ifdef WIN32
+#ifdef _WIN32
// Activate UTF-8 support for Boost filesystem classes on Windows
std::locale::global(boost::locale::generator().generate(""));
boost::filesystem::path::imbue(std::locale());
@@ -10783,7 +10783,7 @@ int main(int argc, char* argv[])
}
else
{
-#ifndef WIN32
+#ifndef _WIN32
// Stopping the console takes the console lock, which the thread receiving
// the signal may already hold. The handler only writes to a pipe, and
// this thread does the actual work.
@@ -10837,7 +10837,7 @@ int main(int argc, char* argv[])
// must be prompting for password so return and let the signal stop prompt
return;
}
-#ifdef WIN32
+#ifdef _WIN32
const bool is_interrupt = type == CTRL_C_EVENT;
#else
const bool is_interrupt = type == SIGINT;
@@ -10862,7 +10862,7 @@ int main(int argc, char* argv[])
});
w.run();
-#ifndef WIN32
+#ifndef _WIN32
stop_signal_thread();
#endif
w.deinit();
### src/wallet/api/wallet.cpp
@@ -48,7 +48,7 @@
#include <sstream>
#include <unordered_map>
-#ifdef WIN32
+#ifdef _WIN32
#include <boost/locale.hpp>
#endif
@@ -404,7 +404,7 @@ uint64_t Wallet::maximumAllowedAmount()
}
void Wallet::init(const char *argv0, const char *default_log_base_name, const std::string &log_path, bool console) {
-#ifdef WIN32
+#ifdef _WIN32
// Activate UTF-8 support for Boost filesystem classes on Windows
std::locale::global(boost::locale::generator().generate(""));
boost::filesystem::path::imbue(std::locale());
### src/wallet/wallet2.cpp
@@ -7365,7 +7365,7 @@ void wallet2::store_to(const std::string &path, const epee::wipeable_string &pas
}
// Save cache to new file. If storing to the same file, the temp path has the ".new" extension
-#ifdef WIN32
+#ifdef _WIN32
// On Windows avoid using std::ofstream which does not work with UTF-8 filenames
// The price to pay is temporary higher memory consumption for string stream + binary archive
std::ostringstream oss;
### src/wallet/wallet_args.cpp
@@ -36,7 +36,7 @@
#include "string_tools.h"
#include "version.h"
-#if defined(WIN32)
+#if defined(_WIN32)
#include <crtdbg.h>
#endif
@@ -93,7 +93,7 @@ namespace wallet_args
{
namespace bf = boost::filesystem;
namespace po = boost::program_options;
-#ifdef WIN32
+#ifdef _WIN32
_CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
#endif
Why this scored 19/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.