changeset 483:85039ab7e6ab

Add simplistic support for DJGPP/DOS.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 19 Feb 2019 06:12:18 +0200
parents 1013ddd2759b
children 58b744131b86
files th_file.c th_util.h
diffstat 2 files changed, 26 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/th_file.c	Tue Feb 19 05:40:14 2019 +0200
+++ b/th_file.c	Tue Feb 19 06:12:18 2019 +0200
@@ -8,9 +8,12 @@
 #include "th_file.h"
 #include "th_string.h"
 #include <unistd.h>
-#ifdef TH_PLAT_WINDOWS
+#if defined(TH_PLAT_WINDOWS)
 #  include <shlwapi.h>
 #  include <shfolder.h>
+#elif defined(TH_PLAT_DOS)
+#  include <sys/stat.h>
+#  include <sys/types.h>
 #else
 //#  include <sys/wait.h>
 #  include <sys/stat.h>
@@ -24,8 +27,11 @@
     char tmpPath[MAX_PATH];
     if (SHGetFolderPath(NULL, CSIDL_APPDATA | CSIDL_FLAG_CREATE, NULL, 0, tmpPath) == S_OK)
         return th_strdup(tmpPath);
+#elif defined(TH_PLAT_DOS)
+    return th_strdup("C:\\");
+#else
+    return th_strdup(getenv("HOME"));
 #endif
-    return th_strdup(getenv("HOME"));
 }
 
 
@@ -35,8 +41,11 @@
     char tmpPath[MAX_PATH];
     if (SHGetFolderPath(NULL, CSIDL_APPDATA | CSIDL_FLAG_CREATE, NULL, 0, tmpPath) == S_OK)
         return th_strdup(tmpPath);
+#elif defined(TH_PLAT_DOS)
+    return th_strdup("C:\\");
+#else
+    return th_strdup(getenv("HOME"));
 #endif
-    return th_strdup(getenv("HOME"));
 }
 
 
@@ -81,7 +90,7 @@
 
 BOOL th_stat_path(const char *path, th_stat_data *data)
 {
-#ifdef TH_PLAT_WINDOWS
+#if defined(TH_PLAT_WINDOWS)
     WIN32_FILE_ATTRIBUTE_DATA fdata;
     if (!GetFileAttributesExA(path, GetFileExInfoStandard, &fdata))
         return FALSE;
@@ -94,9 +103,13 @@
     data->flags  = (fdata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ? TH_IS_DIR : 0;
     data->flags |= (fdata.dwFileAttributes & FILE_ATTRIBUTE_READONLY) ? 0 : TH_IS_WRITABLE;
     data->flags |= TH_IS_READABLE;
+
 #else
+#if defined(TH_PLAT_UNIX)
     uid_t uid = geteuid();
     gid_t gid = getegid();
+#endif
+
     struct stat sb;
     if (stat(path, &sb) < 0)
         return FALSE;
@@ -108,6 +121,7 @@
 
     data->flags  = S_ISDIR(sb.st_mode) ? TH_IS_DIR : 0;
 
+#if defined(TH_PLAT_UNIX)
     if ((uid == sb.st_uid && (sb.st_mode & S_IWUSR)) ||
         (gid == sb.st_gid && (sb.st_mode & S_IWGRP)) ||
         (sb.st_mode & S_IWOTH))
@@ -117,6 +131,10 @@
         (gid == sb.st_gid && (sb.st_mode & S_IRGRP)) ||
         (sb.st_mode & S_IROTH))
         data->flags |= TH_IS_READABLE;
+#elif defined(TH_PLAT_DOS)
+    data->flags |= TH_IS_READABLE | TH_IS_WRITABLE;
+#endif
+
 #endif
 
     return TRUE;
@@ -155,7 +173,7 @@
 
             if (!exists)
             {
-#ifdef TH_PLAT_WINDOWS
+#if defined(TH_PLAT_WINDOWS)
                 if (!CreateDirectory(path, NULL))
                     goto error;
 #else
--- a/th_util.h	Tue Feb 19 05:40:14 2019 +0200
+++ b/th_util.h	Tue Feb 19 06:12:18 2019 +0200
@@ -14,6 +14,9 @@
 
 #if defined(__WIN64) || defined(_WIN64) || defined(__WIN32) || defined(_WIN32)
 #  define TH_PLAT_WINDOWS 1
+#elif defined(__DJGPP__) && __DJGPP__ >= 2
+#  define TH_PLAT_DOS 1
+#  undef __STRICT_ANSI__
 #else
 #  define TH_PLAT_UNIX 1
 #endif