Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #if !defined(DISABLE_STDIO_FILESTREAM)
00024
00025
00026 #define FORBIDDEN_SYMBOL_ALLOW_ALL
00027
00028 #include "backends/fs/stdiostream.h"
00029 #ifdef _WIN32_WCE
00030 #include "backends/platform/wince/missing/fopen.h"
00031 #endif
00032
00033 StdioStream::StdioStream(void *handle) : _handle(handle) {
00034 assert(handle);
00035 }
00036
00037 StdioStream::~StdioStream() {
00038 fclose((FILE *)_handle);
00039 }
00040
00041 bool StdioStream::err() const {
00042 return ferror((FILE *)_handle) != 0;
00043 }
00044
00045 void StdioStream::clearErr() {
00046 clearerr((FILE *)_handle);
00047 }
00048
00049 bool StdioStream::eos() const {
00050 return feof((FILE *)_handle) != 0;
00051 }
00052
00053 int32 StdioStream::pos() const {
00054 return ftell((FILE *)_handle);
00055 }
00056
00057 int32 StdioStream::size() const {
00058 int32 oldPos = ftell((FILE *)_handle);
00059 fseek((FILE *)_handle, 0, SEEK_END);
00060 int32 length = ftell((FILE *)_handle);
00061 fseek((FILE *)_handle, oldPos, SEEK_SET);
00062
00063 return length;
00064 }
00065
00066 bool StdioStream::seek(int32 offs, int whence) {
00067 return fseek((FILE *)_handle, offs, whence) == 0;
00068 }
00069
00070 uint32 StdioStream::read(void *ptr, uint32 len) {
00071 return fread((byte *)ptr, 1, len, (FILE *)_handle);
00072 }
00073
00074 uint32 StdioStream::write(const void *ptr, uint32 len) {
00075 return fwrite(ptr, 1, len, (FILE *)_handle);
00076 }
00077
00078 bool StdioStream::flush() {
00079 return fflush((FILE *)_handle) == 0;
00080 }
00081
00082 StdioStream *StdioStream::makeFromPath(const Common::String &path, bool writeMode) {
00083 FILE *handle = fopen(path.c_str(), writeMode ? "wb" : "rb");
00084
00085 #ifdef __amigaos4__
00086
00087
00088
00089
00090
00091
00092
00093 if (handle && !writeMode) {
00094 setvbuf(handle, NULL, _IOFBF, 8192);
00095 }
00096 #endif
00097
00098 #if defined(__WII__)
00099
00100 if (handle)
00101 setvbuf(handle, NULL, _IONBF, 0);
00102 #endif
00103
00104 if (handle)
00105 return new StdioStream(handle);
00106 return 0;
00107 }
00108
00109 #endif