From 4600f3e6319026f172a4fc5fa8bacec7d512cf2d Mon Sep 17 00:00:00 2001 From: Scott Duensing Date: Mon, 20 Apr 2026 20:30:46 -0500 Subject: [PATCH] Minor platform cleanup. --- .../kpunch/libdvx/platform/dvxPlatformDos.c | 50 ----------------- .../kpunch/libdvx/platform/dvxPlatformUtil.c | 55 +++++++++++++++++++ 2 files changed, 55 insertions(+), 50 deletions(-) diff --git a/src/libs/kpunch/libdvx/platform/dvxPlatformDos.c b/src/libs/kpunch/libdvx/platform/dvxPlatformDos.c index f19289e..a302e77 100644 --- a/src/libs/kpunch/libdvx/platform/dvxPlatformDos.c +++ b/src/libs/kpunch/libdvx/platform/dvxPlatformDos.c @@ -1403,42 +1403,6 @@ void platformLogCrashDetail(int sig, PlatformLogFnT logFn) { } -// Creates a directory and all parent directories that don't exist. -// Works by walking the path from left to right, creating each -// component. mkdir() on an existing directory returns EEXIST which -// is silently ignored. - -int32_t platformMkdirRecursive(const char *path) { - char buf[DVX_MAX_PATH]; - strncpy(buf, path, sizeof(buf) - 1); - buf[sizeof(buf) - 1] = '\0'; - - for (char *p = buf; *p; p++) { - // Skip drive letter (e.g. "C:\") - if (p == buf + 1 && *p == ':') { - continue; - } - - if (*p == '/' || *p == '\\') { - *p = '\0'; - - if (buf[0] != '\0') { - mkdir(buf, 0755); - } - - *p = '/'; - } - } - - // Create the final directory - if (mkdir(buf, 0755) != 0 && errno != EEXIST) { - return -1; - } - - return 0; -} - - // Initializes the INT 33h mouse driver. The mouse driver is a TSR // (or emulated by the DOS environment) that tracks position and // buttons independently of the application. @@ -1871,20 +1835,6 @@ void platformSplashShutdown(void) { } -int32_t platformStripLineEndings(char *buf, int32_t len) { - int32_t dst = 0; - - for (int32_t src = 0; src < len; src++) { - if (buf[src] != '\r') { - buf[dst++] = buf[src]; - } - } - - buf[dst] = '\0'; - return dst; -} - - // DOS 8.3 filename validation. // // Validates that a filename conforms to DOS 8.3 conventions: diff --git a/src/libs/kpunch/libdvx/platform/dvxPlatformUtil.c b/src/libs/kpunch/libdvx/platform/dvxPlatformUtil.c index 6ef6acf..74c07b7 100644 --- a/src/libs/kpunch/libdvx/platform/dvxPlatformUtil.c +++ b/src/libs/kpunch/libdvx/platform/dvxPlatformUtil.c @@ -33,10 +33,12 @@ #include #include +#include #include #include #include #include +#include #include #ifdef __DJGPP__ @@ -180,6 +182,59 @@ char *platformPathDirEnd(const char *path) { } +// Creates a directory and all parent directories that don't exist. +// Walks the path left-to-right, creating each component. mkdir() on +// an existing directory returns EEXIST, which we silently ignore. +// DJGPP-style "C:\" drive letters are handled by skipping the colon +// so we don't try to mkdir("C:") -- harmless on POSIX paths that +// don't start with "X:". +int32_t platformMkdirRecursive(const char *path) { + char buf[DVX_MAX_PATH]; + strncpy(buf, path, sizeof(buf) - 1); + buf[sizeof(buf) - 1] = '\0'; + + for (char *p = buf; *p; p++) { + // Skip drive letter (e.g. "C:\") + if (p == buf + 1 && *p == ':') { + continue; + } + + if (*p == '/' || *p == '\\') { + *p = '\0'; + + if (buf[0] != '\0') { + mkdir(buf, 0755); + } + + *p = '/'; + } + } + + // Create the final directory + if (mkdir(buf, 0755) != 0 && errno != EEXIST) { + return -1; + } + + return 0; +} + + +// Remove carriage returns in-place. Used when reading DOS-format +// text files on hosts that don't auto-strip them. +int32_t platformStripLineEndings(char *buf, int32_t len) { + int32_t dst = 0; + + for (int32_t src = 0; src < len; src++) { + if (buf[src] != '\r') { + buf[dst++] = buf[src]; + } + } + + buf[dst] = '\0'; + return dst; +} + + char *platformReadFile(const char *path, int32_t *outLen) { if (outLen) { *outLen = 0;