ResidualVM logo ResidualVM website - Forums - Contact us BuildBot - Doxygen - Wiki curved edge

stdiostream.cpp

Go to the documentation of this file.
00001 /* ScummVM - Graphic Adventure Engine
00002  *
00003  * ScummVM is the legal property of its developers, whose names
00004  * are too numerous to list here. Please refer to the COPYRIGHT
00005  * file distributed with this source distribution.
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020  *
00021  */
00022 
00023 #if !defined(DISABLE_STDIO_FILESTREAM)
00024 
00025 // Disable symbol overrides so that we can use FILE, fopen etc.
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     // Work around for possibility that someone uses AmigaOS "newlib" build
00088     // with SmartFileSystem (blocksize 512 bytes), leading to buffer size
00089     // being only 512 bytes. "Clib2" sets the buffer size to 8KB, resulting
00090     // smooth movie playback. This forces the buffer to be enough also when
00091     // using "newlib" compile on SFS.
00092     //
00093     if (handle && !writeMode) {
00094         setvbuf(handle, NULL, _IOFBF, 8192);
00095     }
00096 #endif
00097 
00098 #if defined(__WII__)
00099     // disable newlib's buffering, the device libraries handle caching
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


Generated on Sat Nov 30 2019 05:00:22 for ResidualVM by doxygen 1.7.1
curved edge   curved edge