Minor platform cleanup.

This commit is contained in:
Scott Duensing 2026-04-20 20:30:46 -05:00
parent 1affec7e8c
commit 4600f3e631
2 changed files with 55 additions and 50 deletions

View file

@ -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:

View file

@ -33,10 +33,12 @@
#include <ctype.h>
#include <dirent.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <sys/stat.h>
#include <unistd.h>
#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;