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 
00030 StdioStream::StdioStream(void *handle) : _handle(handle) {
00031     assert(handle);
00032 }
00033 
00034 StdioStream::~StdioStream() {
00035     fclose((FILE *)_handle);
00036 }
00037 
00038 bool StdioStream::err() const {
00039     return ferror((FILE *)_handle) != 0;
00040 }
00041 
00042 void StdioStream::clearErr() {
00043     clearerr((FILE *)_handle);
00044 }
00045 
00046 bool StdioStream::eos() const {
00047     return feof((FILE *)_handle) != 0;
00048 }
00049 
00050 int32 StdioStream::pos() const {
00051     return ftell((FILE *)_handle);
00052 }
00053 
00054 int32 StdioStream::size() const {
00055     int32 oldPos = ftell((FILE *)_handle);
00056     fseek((FILE *)_handle, 0, SEEK_END);
00057     int32 length = ftell((FILE *)_handle);
00058     fseek((FILE *)_handle, oldPos, SEEK_SET);
00059 
00060     return length;
00061 }
00062 
00063 bool StdioStream::seek(int32 offs, int whence) {
00064     return fseek((FILE *)_handle, offs, whence) == 0;
00065 }
00066 
00067 uint32 StdioStream::read(void *ptr, uint32 len) {
00068     return fread((byte *)ptr, 1, len, (FILE *)_handle);
00069 }
00070 
00071 uint32 StdioStream::write(const void *ptr, uint32 len) {
00072     return fwrite(ptr, 1, len, (FILE *)_handle);
00073 }
00074 
00075 bool StdioStream::flush() {
00076     return fflush((FILE *)_handle) == 0;
00077 }
00078 
00079 StdioStream *StdioStream::makeFromPath(const Common::String &path, bool writeMode) {
00080     FILE *handle = fopen(path.c_str(), writeMode ? "wb" : "rb");
00081 
00082 #ifdef __amigaos4__
00083     //
00084     // Work around for possibility that someone uses AmigaOS "newlib" build
00085     // with SmartFileSystem (blocksize 512 bytes), leading to buffer size
00086     // being only 512 bytes. "Clib2" sets the buffer size to 8KB, resulting
00087     // smooth movie playback. This forces the buffer to be enough also when
00088     // using "newlib" compile on SFS.
00089     //
00090     if (handle && !writeMode) {
00091         setvbuf(handle, NULL, _IOFBF, 8192);
00092     }
00093 #endif
00094 
00095 #if defined(__WII__)
00096     // disable newlib's buffering, the device libraries handle caching
00097     if (handle)
00098         setvbuf(handle, NULL, _IONBF, 0);
00099 #endif
00100 
00101     if (handle)
00102         return new StdioStream(handle);
00103     return 0;
00104 }
00105 
00106 #endif


Generated on Sat Feb 23 2019 05:01:17 for ResidualVM by doxygen 1.7.1
curved edge   curved edge