aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Horn2007-03-08 16:46:02 +0000
committerMax Horn2007-03-08 16:46:02 +0000
commit743698da6ecb1b27f9fd3ee0c808c7d64f4ff535 (patch)
treee8ba1c88bf6f6e5e30bd5f82079bad7d7cc3dab2
parent33a4f8c378ed5868a4343114d47649d11cf75ac0 (diff)
downloadscummvm-rg350-743698da6ecb1b27f9fd3ee0c808c7d64f4ff535.tar.gz
scummvm-rg350-743698da6ecb1b27f9fd3ee0c808c7d64f4ff535.tar.bz2
scummvm-rg350-743698da6ecb1b27f9fd3ee0c808c7d64f4ff535.zip
Changed File::_handle to be of type void* instead of FILE* (to ease porting); moved PS2 std C I/O defines to file.cpp (no code other than the file & savegame code should use fopen etc. directly)
svn-id: r26017
-rw-r--r--common/file.cpp45
-rw-r--r--common/file.h4
-rw-r--r--common/scummsys.h26
3 files changed, 36 insertions, 39 deletions
diff --git a/common/file.cpp b/common/file.cpp
index aecc1cf8d3..d0538b2bb6 100644
--- a/common/file.cpp
+++ b/common/file.cpp
@@ -30,6 +30,29 @@
#include "CoreFoundation/CoreFoundation.h"
#endif
+#ifdef __PLAYSTATION2__
+ // for those replaced fopen/fread/etc functions
+ typedef unsigned long uint64;
+ typedef signed long int64;
+ #include "backends/platform/ps2/fileio.h"
+
+ #define fopen(a, b) ps2_fopen(a, b)
+ #define fclose(a) ps2_fclose(a)
+ #define fflush(a) ps2_fflush(a)
+ #define fseek(a, b, c) ps2_fseek(a, b, c)
+ #define ftell(a) ps2_ftell(a)
+ #define feof(a) ps2_feof(a)
+ #define fread(a, b, c, d) ps2_fread(a, b, c, d)
+ #define fwrite(a, b, c, d) ps2_fwrite(a, b, c, d)
+ #define fgetc(a) ps2_fgetc(a)
+ #define fgets(a, b, c) ps2_fgets(a, b, c)
+ #define fputc(a, b) ps2_fputc(a, b)
+ #define fputs(a, b) ps2_fputs(a, b)
+ #define fprintf ps2_fprintf
+ #define fsize(a) ps2_fsize(a)
+#endif
+
+
namespace Common {
typedef HashMap<String, int, CaseSensitiveString_Hash, CaseSensitiveString_EqualTo> StringIntMap;
@@ -337,7 +360,7 @@ bool File::exists(const String &filename) {
void File::close() {
if (_handle)
- fclose(_handle);
+ fclose((FILE *)_handle);
_handle = NULL;
}
@@ -359,7 +382,7 @@ bool File::eof() const {
return false;
}
- return feof(_handle) != 0;
+ return feof((FILE *)_handle) != 0;
}
uint32 File::pos() const {
@@ -368,7 +391,7 @@ uint32 File::pos() const {
return 0;
}
- return ftell(_handle);
+ return ftell((FILE *)_handle);
}
uint32 File::size() const {
@@ -377,10 +400,10 @@ uint32 File::size() const {
return 0;
}
- uint32 oldPos = ftell(_handle);
- fseek(_handle, 0, SEEK_END);
- uint32 length = ftell(_handle);
- fseek(_handle, oldPos, SEEK_SET);
+ uint32 oldPos = ftell((FILE *)_handle);
+ fseek((FILE *)_handle, 0, SEEK_END);
+ uint32 length = ftell((FILE *)_handle);
+ fseek((FILE *)_handle, oldPos, SEEK_SET);
return length;
}
@@ -391,8 +414,8 @@ void File::seek(int32 offs, int whence) {
return;
}
- if (fseek(_handle, offs, whence) != 0)
- clearerr(_handle);
+ if (fseek((FILE *)_handle, offs, whence) != 0)
+ clearerr((FILE *)_handle);
}
uint32 File::read(void *ptr, uint32 len) {
@@ -407,7 +430,7 @@ uint32 File::read(void *ptr, uint32 len) {
if (len == 0)
return 0;
- real_len = fread(ptr2, 1, len, _handle);
+ real_len = fread(ptr2, 1, len, (FILE *)_handle);
if (real_len < len) {
_ioFailed = true;
}
@@ -424,7 +447,7 @@ uint32 File::write(const void *ptr, uint32 len) {
if (len == 0)
return 0;
- if ((uint32)fwrite(ptr, 1, len, _handle) != len) {
+ if ((uint32)fwrite(ptr, 1, len, (FILE *)_handle) != len) {
_ioFailed = true;
}
diff --git a/common/file.h b/common/file.h
index 2b41522c2b..c5371098c5 100644
--- a/common/file.h
+++ b/common/file.h
@@ -34,8 +34,8 @@ namespace Common {
class File : public SeekableReadStream, public WriteStream {
protected:
- /** POSIX file handle to the actual file; 0 if no file is open. */
- FILE *_handle;
+ /** File handle to the actual file; 0 if no file is open. */
+ void *_handle;
/** Status flag which tells about recent I/O failures. */
bool _ioFailed;
diff --git a/common/scummsys.h b/common/scummsys.h
index d586e9795a..e758b82288 100644
--- a/common/scummsys.h
+++ b/common/scummsys.h
@@ -279,21 +279,6 @@
#define SCUMM_LITTLE_ENDIAN
#define SCUMM_NEED_ALIGNMENT
- #define fopen(a, b) ps2_fopen(a, b)
- #define fclose(a) ps2_fclose(a)
- #define fflush(a) ps2_fflush(a)
- #define fseek(a, b, c) ps2_fseek(a, b, c)
- #define ftell(a) ps2_ftell(a)
- #define feof(a) ps2_feof(a)
- #define fread(a, b, c, d) ps2_fread(a, b, c, d)
- #define fwrite(a, b, c, d) ps2_fwrite(a, b, c, d)
- #define fgetc(a) ps2_fgetc(a)
- #define fgets(a, b, c) ps2_fgets(a, b, c)
- #define fputc(a, b) ps2_fputc(a, b)
- #define fputs(a, b) ps2_fputs(a, b)
- #define fprintf ps2_fprintf
- #define fsize(a) ps2_fsize(a)
-
#elif defined(__PSP__)
#define scumm_stricmp strcasecmp
@@ -407,16 +392,5 @@
typedef int16 OverlayColor;
#endif
-#ifdef __PLAYSTATION2__
- // for libmpeg2...
- typedef uint8 uint8_t;
- typedef uint32 uint32_t;
-
- // for those replaced fopen/fread/etc functions
- typedef unsigned long uint64;
- typedef signed long int64;
- #include "backends/platform/ps2/fileio.h"
-#endif
-
#endif