- Win32Types.h: fixed-width Win32 scalars, pointer-sized handles, static_asserts
- Win32Crt.{h,cpp}: MSVC _snprintf truncation contract, stricmp, timeGetTime wrap
- port_logic static lib linked into libmtgodot; standalone MTGODOT_BUILD_PORT build
- port_header_gate: every port/**.h compiles alone (twice) with its lib's
40250 Distribute|Win32 defines (NDEBUG, USE_LOD, _DISTRIBUTE)
- script/port_gate.sh: macOS/Android/iOS/Windows(mingw) PASS, Linux BLOCKED
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
64 lines
1.3 KiB
C++
64 lines
1.3 KiB
C++
#include "Win32Crt.h"
|
|
|
|
#if !defined(_WIN32)
|
|
#include <cctype>
|
|
#include <chrono>
|
|
#include <cstdio>
|
|
#include <vector>
|
|
|
|
char* _strlwr(char* s)
|
|
{
|
|
for (char* p = s; *p; ++p)
|
|
*p = static_cast<char>(std::tolower(static_cast<unsigned char>(*p)));
|
|
return s;
|
|
}
|
|
|
|
char* _strupr(char* s)
|
|
{
|
|
for (char* p = s; *p; ++p)
|
|
*p = static_cast<char>(std::toupper(static_cast<unsigned char>(*p)));
|
|
return s;
|
|
}
|
|
|
|
int _vsnprintf(char* buf, size_t count, const char* fmt, va_list ap)
|
|
{
|
|
va_list probe;
|
|
va_copy(probe, ap);
|
|
const int len = std::vsnprintf(nullptr, 0, fmt, probe);
|
|
va_end(probe);
|
|
if (len < 0)
|
|
return -1;
|
|
|
|
const size_t need = static_cast<size_t>(len);
|
|
if (need < count)
|
|
return std::vsnprintf(buf, count, fmt, ap);
|
|
|
|
std::vector<char> full(need + 1);
|
|
std::vsnprintf(full.data(), full.size(), fmt, ap);
|
|
std::memcpy(buf, full.data(), count);
|
|
return need == count ? len : -1;
|
|
}
|
|
|
|
int _snprintf(char* buf, size_t count, const char* fmt, ...)
|
|
{
|
|
va_list ap;
|
|
va_start(ap, fmt);
|
|
const int ret = _vsnprintf(buf, count, fmt, ap);
|
|
va_end(ap);
|
|
return ret;
|
|
}
|
|
|
|
DWORD timeGetTime()
|
|
{
|
|
using namespace std::chrono;
|
|
const auto ms = duration_cast<milliseconds>(steady_clock::now().time_since_epoch()).count();
|
|
return static_cast<DWORD>(static_cast<uint64_t>(ms));
|
|
}
|
|
|
|
DWORD GetTickCount()
|
|
{
|
|
return timeGetTime();
|
|
}
|
|
|
|
#endif // !_WIN32
|