[Scummvm-cvs-logs] SF.net SVN: scummvm:[46115] scummvm/trunk/backends/platform/ps2

fingolfin at users.sourceforge.net fingolfin at users.sourceforge.net
Tue Nov 24 00:32:34 CET 2009


Revision: 46115
          http://scummvm.svn.sourceforge.net/scummvm/?rev=46115&view=rev
Author:   fingolfin
Date:     2009-11-23 23:32:34 +0000 (Mon, 23 Nov 2009)

Log Message:
-----------
PS2: Further tweak PS2FileStream; fix potential leak in ps2_fopen

Modified Paths:
--------------
    scummvm/trunk/backends/platform/ps2/fileio.cpp
    scummvm/trunk/backends/platform/ps2/fileio.h

Modified: scummvm/trunk/backends/platform/ps2/fileio.cpp
===================================================================
--- scummvm/trunk/backends/platform/ps2/fileio.cpp	2009-11-23 23:26:16 UTC (rev 46114)
+++ scummvm/trunk/backends/platform/ps2/fileio.cpp	2009-11-23 23:32:34 UTC (rev 46115)
@@ -431,17 +431,70 @@
 
 
 PS2FileStream *PS2FileStream::makeFromPath(const Common::String &path, bool writeMode) {
-	FILE *handle = ps2_fopen(path.c_str(), writeMode ? "wb" : "rb");
+	Ps2File *file = new Ps2File();
 
-	if (handle)
-		return new PS2FileStream(handle);
+	int mode = writeMode ? (O_WRONLY | O_CREAT) : O_RDONLY;
+
+	if (file->open(path.c_str(), mode))
+		return new PS2FileStream(file);
+
+	delete file;
 	return 0;
 }
 
-PS2FileStream::PS2FileStream(FILE *handle) : _handle(handle) {
+PS2FileStream::PS2FileStream(Ps2File *handle) : _handle(handle) {
 	assert(handle);
 }
 
+PS2FileStream::~PS2FileStream() {
+	delete _handle;
+}
+
+bool PS2FileStream::seek(int32 offs, int whence) {
+	return _handle->seek(offs, whence) == 0;
+}
+
+int32 PS2FileStream::pos() const {
+	return _handle->tell();
+}
+
+bool PS2FileStream::eos() const {
+	return _handle->eof();
+}
+
+uint32 PS2FileStream::read(void *ptr, uint32 len) {
+	return _handle->read(ptr, len);
+}
+
+uint32 PS2FileStream::write(const void *ptr, uint32 len) {
+	return _handle->write(ptr, len);
+}
+
+bool PS2FileStream::flush() {
+	// printf("flush not implemented\n");
+	return true;
+}
+
+bool PS2FileStream::err() const {
+	bool errVal = _handle->getErr();
+
+	if (errVal) {
+		printf("ferror -> %d\n", errVal);
+	}
+
+	return errVal;
+}
+
+void PS2FileStream::clearErr() {
+	_handle->setErr(false);
+}
+
+int32 PS2FileStream::size() const {
+	return _handle->size();
+}
+
+
+
 FILE *ps2_fopen(const char *fname, const char *mode) {
 	Ps2File *file = new Ps2File();
 	int _mode = O_RDONLY;
@@ -457,12 +510,9 @@
 
 	if (file->open(fname, _mode))
 		return (FILE *)file;
-	else
-		return NULL;
-}
 
-PS2FileStream::~PS2FileStream() {
-	ps2_fclose(_handle);
+	delete file;
+	return NULL;
 }
 
 int ps2_fclose(FILE *stream) {
@@ -473,31 +523,12 @@
 	return 0;
 }
 
-bool PS2FileStream::seek(int32 offs, int whence) {
-	return ((Ps2File*)_handle)->seek(offs, whence) == 0;
-}
 
-int32 PS2FileStream::pos() const {
-	return ((Ps2File*)_handle)->tell();
-}
-
-bool PS2FileStream::eos() const {
-	return ((Ps2File*)_handle)->eof();
-}
-
-uint32 PS2FileStream::read(void *ptr, uint32 len) {
-	return ps2_fread((byte *)ptr, 1, len, _handle);
-}
-
 size_t ps2_fread(void *buf, size_t r, size_t n, FILE *stream) {
 	assert(r != 0);
 	return ((Ps2File*)stream)->read(buf, r * n) / r;
 }
 
-uint32 PS2FileStream::write(const void *ptr, uint32 len) {
-	return ps2_fwrite(ptr, 1, len, _handle);
-}
-
 size_t ps2_fwrite(const void *buf, size_t r, size_t n, FILE *stream) {
 	assert(r != 0);
 	return ((Ps2File*)stream)->write(buf, r * n) / r;
@@ -518,29 +549,7 @@
 		return EOF;
 }
 
-bool PS2FileStream::flush() {
-	return ps2_fflush(_handle) == 0;
-}
-
 int ps2_fflush(FILE *stream) {
 	// printf("fflush not implemented\n");
 	return 0;
 }
-
-bool PS2FileStream::err() const {
-	int errVal = ((Ps2File*)_handle)->getErr();
-
-	if (errVal) {
-		printf("ferror -> %d\n", errVal);
-	}
-
-	return errVal != 0;
-}
-
-void PS2FileStream::clearErr() {
-	((Ps2File*)_handle)->setErr(false);
-}
-
-int32 PS2FileStream::size() const {
-	return ((Ps2File*)_handle)->size();
-}

Modified: scummvm/trunk/backends/platform/ps2/fileio.h
===================================================================
--- scummvm/trunk/backends/platform/ps2/fileio.h	2009-11-23 23:26:16 UTC (rev 46114)
+++ scummvm/trunk/backends/platform/ps2/fileio.h	2009-11-23 23:32:34 UTC (rev 46115)
@@ -90,7 +90,7 @@
 class PS2FileStream : public Common::SeekableReadStream, public Common::WriteStream, public Common::NonCopyable {
 protected:
 	/** File handle to the actual file. */
-	FILE *_handle;
+	Ps2File *_handle;
 
 public:
 	/**
@@ -99,7 +99,7 @@
 	 */
 	static PS2FileStream *makeFromPath(const Common::String &path, bool writeMode);
 
-	PS2FileStream(FILE *handle);
+	PS2FileStream(Ps2File *handle);
 	virtual ~PS2FileStream();
 
 	virtual bool err() const;


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list