# HG changeset patch # User Matti Hamalainen # Date 1550549538 -7200 # Node ID 85039ab7e6ab7b9be5b11c0585812c9a9f26c61d # Parent 1013ddd2759be4dfd4a32c34478fc9c6f647249d Add simplistic support for DJGPP/DOS. diff -r 1013ddd2759b -r 85039ab7e6ab th_file.c --- 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 -#ifdef TH_PLAT_WINDOWS +#if defined(TH_PLAT_WINDOWS) # include # include +#elif defined(TH_PLAT_DOS) +# include +# include #else //# include # include @@ -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 diff -r 1013ddd2759b -r 85039ab7e6ab th_util.h --- 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