1 /* GemRB - Infinity Engine Emulator
2 * Copyright (C) 2003 The GemRB Project
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 * Compatibility layer for file and dir access functions on Un*x and MS Win
24 * @author The GemRB Project
34 #define _MAX_PATH FILENAME_MAX
56 typedef struct _FILE
{
60 GEM_EXPORT _FILE
* _fopen(const char* filename
, const char* mode
);
61 GEM_EXPORT
size_t _fread(void* ptr
, size_t size
, size_t n
, _FILE
* stream
);
62 GEM_EXPORT
size_t _fwrite(const void* ptr
, size_t size
, size_t n
,
64 GEM_EXPORT
size_t _fseek(_FILE
* stream
, long offset
, int whence
);
65 GEM_EXPORT
int _fgetc(_FILE
* stream
);
66 GEM_EXPORT
long int _ftell(_FILE
* stream
);
67 GEM_EXPORT
int _feof(_FILE
* stream
);
68 GEM_EXPORT
int _fclose(_FILE
* stream
);
69 #define mkdir(path, rights) _mkdir(path)
70 #define ResolveFilePath(p)
77 #define _fwrite fwrite
82 #define _fclose fclose
84 /** Handle ~ -> $HOME mapping and do initial case-sensitity check */
85 GEM_EXPORT
void ResolveFilePath(char* FilePath
);
86 GEM_EXPORT
void ResolveFilePath(std::string
& FilePath
);
91 const char PathDelimiter
= '\\';
92 const char PathListSeparator
= ';';
94 const char PathDelimiter
= '/';
95 const char PathListSeparator
= ':';
97 const char SPathDelimiter
[] = { PathDelimiter
, '\0' };
98 const char SPathListSeparator
[] = { PathListSeparator
, '\0' };
101 * Finds a file matching a glob.
103 * @param[out] target name of matching file
104 * @param[in] Dir directory to look in
105 * @param[in] glob pattern to match
106 * @return true if match is found
108 GEM_EXPORT
bool FileGlob(char *target
, const char* Dir
, const char* glob
);
109 GEM_EXPORT
bool dir_exists(const char* path
);
110 GEM_EXPORT
bool file_exists(const char* path
);
113 * Joins NULL-terminated list of directories and copies it to 'target'.
115 * @param[out] target Joined path.
116 * @param[in] base Properly cased path to join to.
117 * @param[in] ... NULL terminated list of paths to join.
119 * This does a case-sensitive look up for all path components after the first and
120 * properly handles the case when paramater contain slashes.
122 * NOTE: This no longer handles target==base.
125 * char filepath[_MAX_PATH];
126 * PathJoin( filepath, core->GUIScriptsPath, core->GameType, 'GUIDefines.py', NULL );
128 GEM_EXPORT
bool PathJoin (char* target
, const char* base
, ...);
129 GEM_EXPORT
bool PathJoinExt (char* target
, const char* dir
, const char* file
, const char* ext
= NULL
);
130 GEM_EXPORT
void FixPath (char *path
, bool needslash
);
132 GEM_EXPORT
void ExtractFileFromPath(char *file
, const char *full_path
);
134 class DirectoryIterator
{
137 * @param[in] path Path to direcrtory to search.
139 * WARNING: the lifetime of path must be longer than the lifetime
140 * of DirectoryIterator.
142 DirectoryIterator(const char *path
);
143 ~DirectoryIterator();
146 * Returns name of current entry.
148 * The returned string is only valid until the iterator is advanced.
149 * FIXME: This should return a const char*
152 void GetFullPath(char *);
153 DirectoryIterator
& operator++();
154 #include "operatorbool.h"
155 OPERATOR_BOOL(DirectoryIterator
,void,Entry
)
156 bool operator !() { return !Entry
; }