DOSBox-X
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator
include/cross.h
00001 /*
00002  *  Copyright (C) 2002-2015  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
00015  *  along with this program; if not, write to the Free Software
00016  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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& temp);
00081         static bool IsPathAbsolute(std::string const& in);
00082 };
00083 
00084 
00085 #if defined (WIN32)
00086 
00087 #define WIN32_LEAN_AND_MEAN        // Exclude rarely-used stuff from 
00088 #include <windows.h>
00089 
00090 typedef struct dir_struct {
00091         HANDLE          handle;
00092         char            base_path[(MAX_PATH+4)*sizeof(wchar_t)];
00093     wchar_t *wbase_path(void) {
00094         return (wchar_t*)base_path;
00095     }
00096     // TODO: offer a config.h option to opt out of Windows widechar functions
00097     union {
00098         WIN32_FIND_DATAA a;
00099         WIN32_FIND_DATAW w;
00100     } search_data;
00101     bool            wide;
00102 } dir_information;
00103 
00104 // TODO: offer a config.h option to opt out of Windows widechar functions
00105 dir_information* open_directory(const char* dirname);
00106 bool read_directory_first(dir_information* dirp, char* entry_name, bool& is_directory);
00107 bool read_directory_next(dir_information* dirp, char* entry_name, bool& is_directory);
00108 dir_information* open_directoryw(const wchar_t* dirname);
00109 bool read_directory_firstw(dir_information* dirp, wchar_t* entry_name, bool& is_directory);
00110 bool read_directory_nextw(dir_information* dirp, wchar_t* entry_name, bool& is_directory);
00111 
00112 #else
00113 
00114 //#include <sys/types.h> //Included above
00115 #include <dirent.h>
00116 
00117 typedef struct dir_struct { 
00118         DIR*  dir;
00119         char base_path[CROSS_LEN];
00120 } dir_information;
00121 
00122 dir_information* open_directory(const char* dirname);
00123 bool read_directory_first(dir_information* dirp, char* entry_name, bool& is_directory);
00124 bool read_directory_next(dir_information* dirp, char* entry_name, bool& is_directory);
00125 #define open_directoryw open_directory
00126 #define read_directory_firstw read_directory_first
00127 #define read_directory_nextw read_directory_next
00128 
00129 #endif
00130 
00131 void close_directory(dir_information* dirp);
00132 
00133 #endif