From 2877207e19f077f2edddf522e2faa950c8aa05ab Mon Sep 17 00:00:00 2001 From: Yagiz Nizipli Date: Tue, 22 Apr 2025 12:02:17 -0400 Subject: [PATCH] src: move windows specific fns to `_WIN32` PR-URL: https://github.com/nodejs/node/pull/57951 Reviewed-By: James M Snell Reviewed-By: Pietro Marchini Reviewed-By: Luigi Pinca Reviewed-By: Stefan Stojanovic --- src/util-inl.h | 12 +++++------- src/util.h | 3 +++ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/util-inl.h b/src/util-inl.h index d400d913be7..44dbceed5f3 100644 --- a/src/util-inl.h +++ b/src/util-inl.h @@ -28,10 +28,13 @@ #include #include #include -#include // NOLINT(build/c++11) #include "node_revert.h" #include "util.h" +#ifdef _WIN32 +#include // NOLINT(build/c++11) +#endif // _WIN32 + #define CHAR_TEST(bits, name, expr) \ template \ bool name(const T ch) { \ @@ -588,9 +591,8 @@ constexpr std::string_view FastStringKey::as_string_view() const { return name_; } -// Inline so the compiler can fully optimize it away on Unix platforms. -bool IsWindowsBatchFile(const char* filename) { #ifdef _WIN32 +inline bool IsWindowsBatchFile(const char* filename) { std::string file_with_extension = filename; // Regex to match the last extension part after the last dot, ignoring // trailing spaces and dots @@ -603,12 +605,8 @@ bool IsWindowsBatchFile(const char* filename) { } return !extension.empty() && (extension == "cmd" || extension == "bat"); -#else - return false; -#endif // _WIN32 } -#ifdef _WIN32 inline std::wstring ConvertToWideString(const std::string& str, UINT code_page) { int size_needed = MultiByteToWideChar( diff --git a/src/util.h b/src/util.h index 876eefd9c0d..7e575605cb7 100644 --- a/src/util.h +++ b/src/util.h @@ -1026,9 +1026,12 @@ v8::Maybe GetValidFileMode(Environment* env, v8::Local input, uv_fs_type type); +#ifdef _WIN32 // Returns true if OS==Windows and filename ends in .bat or .cmd, // case insensitive. inline bool IsWindowsBatchFile(const char* filename); +inline std::wstring ConvertToWideString(const std::string& str, UINT code_page); +#endif // _WIN32 } // namespace node