port(2A): port/common Win32 layer, port_logic target and header gate

- 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>
This commit is contained in:
shenlei
2026-09-22 19:57:58 +09:00
co-authored by Claude Opus 5
parent 4521845a69
commit 2bae8d7644
11 changed files with 498 additions and 1 deletions
+41
View File
@@ -0,0 +1,41 @@
#pragma once
// The Win32/MSVC-CRT functions and macros that 40250 logic code calls, with MSVC semantics.
// Added on demand as ported units need them; each one keeps the Windows behavior (including
// the legacy `_snprintf` truncation contract), not the nearest POSIX spelling.
#include "Win32Types.h"
#include <cstdarg>
#include <cstring>
#if !defined(_WIN32)
#include <strings.h>
#define ZeroMemory(dst, len) std::memset((dst), 0, (len))
#define FillMemory(dst, len, fill) std::memset((dst), (fill), (len))
#define CopyMemory(dst, src, len) std::memcpy((dst), (src), (len))
#define MoveMemory(dst, src, len) std::memmove((dst), (src), (len))
inline int _stricmp(const char* a, const char* b) { return strcasecmp(a, b); }
inline int stricmp(const char* a, const char* b) { return strcasecmp(a, b); }
inline int _strnicmp(const char* a, const char* b, size_t n) { return strncasecmp(a, b, n); }
inline int strnicmp(const char* a, const char* b, size_t n) { return strncasecmp(a, b, n); }
char* _strlwr(char* s);
char* _strupr(char* s);
// MSVC `_snprintf`/`_vsnprintf`: when the output is longer than `count`, `count` bytes are written
// with no terminator and -1 is returned; exactly `count` bytes are written unterminated and
// `count` is returned; otherwise the output is terminated and its length returned.
int _vsnprintf(char* buf, size_t count, const char* fmt, va_list ap);
int _snprintf(char* buf, size_t count, const char* fmt, ...)
#if defined(__GNUC__)
__attribute__((format(printf, 3, 4)))
#endif
;
// winmm `timeGetTime`: milliseconds since system start, wrapping at 2^32.
DWORD timeGetTime();
DWORD GetTickCount();
#endif // !_WIN32