[Scummvm-cvs-logs] CVS: scummvm/scumm script_v5.cpp,1.124,1.125

Max Horn fingolfin at users.sourceforge.net
Sat Jun 21 13:28:09 CEST 2003


Update of /cvsroot/scummvm/scummvm/scumm
In directory sc8-pr-cvs1:/tmp/cvs-serv26792

Modified Files:
	script_v5.cpp 
Log Message:
finally implemented this TODO: using class File instead of fopen

Index: script_v5.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scumm/script_v5.cpp,v
retrieving revision 1.124
retrieving revision 1.125
diff -u -d -r1.124 -r1.125
--- script_v5.cpp	20 Jun 2003 11:14:18 -0000	1.124
+++ script_v5.cpp	21 Jun 2003 20:27:48 -0000	1.125
@@ -1755,50 +1755,37 @@
 		break;
 
 	case 13:{										/* save-string */
-			// TODO - use class File instead of fopen/fwrite/fclose
-			char buf[256], *s;
-			FILE *out;
+			File file;
+			char filename[256], *s;
 
 			a = getVarOrDirectByte(0x80);
 
-			// FIXME - check for buffer overflow
-			strcpy(buf, getSavePath());
-			s = buf + strlen(buf);
+			s = filename;
 			while ((*s++ = fetchScriptByte()));
 
-			// Use buf as filename
-			out = fopen(buf, "wb");
-			if (out) {
+			file.open(filename, getSavePath(), File::kFileWriteMode);
+			if (file.isOpen()) {
 				byte *ptr;
 				ptr = getResourceAddress(rtString, a);
-				fwrite(ptr, resStrLen(ptr) + 1, 1, out);
-				fclose(out);
+				file.write(ptr, resStrLen(ptr) + 1);
 			}
 			break;
 		}
 	case 14:{										/* load-string */
-			// TODO - use class File instead of fopen/fread/fclose
-			char buf[256], *s;
-			FILE *in;
+			File file;
+			char filename[256], *s;
 
 			a = getVarOrDirectByte(0x80);
 
-			// FIXME - check for buffer overflow
-			strcpy(buf, getSavePath());
-			s = buf + strlen(buf);
+			s = filename;
 			while ((*s++ = fetchScriptByte()));
 
-			// Use buf as filename
-			in = fopen(buf, "rb");
-			if (in) {
+			file.open(filename, getSavePath(), File::kFileReadMode);
+			if (file.isOpen()) {
 				byte *ptr;
-				int len;
-				fseek(in, 0, SEEK_END);
-				len = ftell(in);				// Determine file size
+				int len = file.size();
 				ptr = (byte *)calloc(len + 1, 1);	// Create a zero terminated buffer
-				fseek(in, 0, SEEK_SET);
-				fread(ptr, len, 1, in);	// Read in the data
-				fclose(in);
+				file.read(ptr, len);	// Read in the data
 				loadPtrToResource(rtString, a, ptr);
 				free(ptr);
 			}





More information about the Scummvm-git-logs mailing list