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 bool StdioStream::setBufferSize(uint32 bufferSize) {
00072     if (bufferSize != 0) {
00073         return setvbuf((FILE *)_handle, nullptr, _IOFBF, bufferSize) == 0;
00074     } else {
00075         return setvbuf((FILE *)_handle, nullptr, _IONBF, 0) == 0;
00076     }
00077 }
00078 
00079 uint32 StdioStream::write(const void *ptr, uint32 len) {
00080     return fwrite(ptr, 1, len, (FILE *)_handle);
00081 }
00082 
00083 bool StdioStream::flush() {
00084     return fflush((FILE *)_handle) == 0;
00085 }
00086 
00087 StdioStream *StdioStream::makeFromPath(const Common::String &path, bool writeMode) {
00088     FILE *handle = fopen(path.c_str(), writeMode ? "wb" : "rb");
00089 
00090     if (handle)
00091         return new StdioStream(handle);
00092     return 0;
00093 }
00094 
00095 #endif


Generated on Sat May 30 2020 05:00:31 for ResidualVM by doxygen 1.7.1
curved edge   curved edge