DOSBox-X
|
00001 /* 00002 * Copyright (C) 2002-2020 The DOSBox Team 00003 * 00004 * This program is free software; you can redistribute it and/or modify 00005 * it under the terms of the GNU General Public License as published by 00006 * the Free Software Foundation; either version 2 of the License, or 00007 * (at your option) any later version. 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License along 00015 * with this program; if not, write to the Free Software Foundation, Inc., 00016 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00017 */ 00018 00019 00020 #ifndef DOSBOX_CROSS_H 00021 #define DOSBOX_CROSS_H 00022 00023 #ifndef DOSBOX_DOSBOX_H 00024 #include "dosbox.h" 00025 #endif 00026 00027 #include <stdio.h> 00028 #include <sys/stat.h> 00029 #include <sys/types.h> 00030 #include <string> 00031 00032 #if defined (_MSC_VER) /* MS Visual C++ */ 00033 #include <direct.h> 00034 #include <io.h> 00035 #define ULONGTYPE(a) a##ULL 00036 #define LONGTYPE(a) a##LL 00037 #define snprintf _snprintf 00038 #define vsnprintf _vsnprintf 00039 #define alloca _alloca 00040 #define putenv _putenv 00041 #else /* LINUX / GCC */ 00042 #include <dirent.h> 00043 #include <unistd.h> 00044 #define ULONGTYPE(a) a##ULL 00045 #define LONGTYPE(a) a##LL 00046 #endif 00047 00048 #define CROSS_LEN 512 /* Maximum filename size */ 00049 00050 00051 #if defined (WIN32) || defined (OS2) /* Win 32 & OS/2*/ 00052 #define CROSS_FILENAME(blah) 00053 #define CROSS_FILESPLIT '\\' 00054 #define F_OK 0 00055 #else 00056 #define CROSS_FILENAME(blah) strreplace(blah,'\\','/') 00057 #define CROSS_FILESPLIT '/' 00058 #endif 00059 00060 #define CROSS_NONE 0 00061 #define CROSS_FILE 1 00062 #define CROSS_DIR 2 00063 #if defined (WIN32) && !defined (__MINGW32__) 00064 #define ftruncate(blah,blah2) chsize(blah,blah2) 00065 #endif 00066 00067 //Solaris maybe others 00068 #if defined (DB_HAVE_NO_POWF) 00069 #include <math.h> 00070 static inline float powf (float x, float y) { return (float) pow (x,y); } 00071 #endif 00072 00073 class Cross { 00074 public: 00075 static void GetPlatformResDir(std::string& in); 00076 static void GetPlatformConfigDir(std::string& in); 00077 static void GetPlatformConfigName(std::string& in); 00078 static void CreatePlatformConfigDir(std::string& in); 00079 static void ResolveHomedir(std::string & temp_line); 00080 static void CreateDir(std::string const& in); 00081 static bool IsPathAbsolute(std::string const& in); 00082 }; 00083 00084 00085 #if defined (WIN32) 00086 00087 #ifndef WIN32_LEAN_AND_MEAN 00088 #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from 00089 #endif 00090 00091 #include <windows.h> 00092 00093 typedef struct dir_struct { 00094 HANDLE handle; 00095 char base_path[(MAX_PATH+4)*sizeof(wchar_t)]; 00096 wchar_t *wbase_path(void) { 00097 return (wchar_t*)base_path; 00098 } 00099 // TODO: offer a config.h option to opt out of Windows widechar functions 00100 union { 00101 WIN32_FIND_DATAA a; 00102 WIN32_FIND_DATAW w; 00103 } search_data; 00104 bool wide; 00105 } dir_information; 00106 00107 // TODO: offer a config.h option to opt out of Windows widechar functions 00108 dir_information* open_directory(const char* dirname); 00109 bool read_directory_first(dir_information* dirp, char* entry_name, char* entry_sname, bool& is_directory); 00110 bool read_directory_next(dir_information* dirp, char* entry_name, char* entry_sname, bool& is_directory); 00111 dir_information* open_directoryw(const wchar_t* dirname); 00112 bool read_directory_firstw(dir_information* dirp, wchar_t* entry_name, wchar_t* entry_sname, bool& is_directory); 00113 bool read_directory_nextw(dir_information* dirp, wchar_t* entry_name, wchar_t* entry_sname, bool& is_directory); 00114 00115 #else 00116 00117 //#include <sys/types.h> //Included above 00118 #include <dirent.h> 00119 00120 typedef struct dir_struct { 00121 DIR* dir; 00122 char base_path[CROSS_LEN]; 00123 } dir_information; 00124 00125 dir_information* open_directory(const char* dirname); 00126 bool read_directory_first(dir_information* dirp, char* entry_name, char* entry_sname, bool& is_directory); 00127 bool read_directory_next(dir_information* dirp, char* entry_name, char* entry_sname, bool& is_directory); 00128 00129 #define open_directoryw open_directory 00130 #define read_directory_firstw read_directory_first 00131 #define read_directory_nextw read_directory_next 00132 00133 #endif 00134 00135 void close_directory(dir_information* dirp); 00136 00137 FILE* fopen_wrap(const char* path, const char* mode); 00138 #endif