[Scummvm-cvs-logs] CVS: scummvm/common md5.cpp,1.4,1.5 md5.h,1.4,1.5

Eugene Sandulenko sev at users.sourceforge.net
Wed Dec 22 05:35:06 CET 2004


Update of /cvsroot/scummvm/scummvm/common
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1238

Modified Files:
	md5.cpp md5.h 
Log Message:
Now it is possible to count MD5 only for specified amount of bytes from file.
It is useful for MD5'ing hunge files.


Index: md5.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/common/md5.cpp,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- md5.cpp	29 Jun 2004 12:07:14 -0000	1.4
+++ md5.cpp	22 Dec 2004 13:34:28 -0000	1.5
@@ -239,12 +239,14 @@
     PUT_UINT32( ctx->state[3], digest, 12 );
 }
 
-bool md5_file( const char *name, uint8 digest[16], const char *directory )
+bool md5_file( const char *name, uint8 digest[16], const char *directory, uint32 length )
 {
     File f;
     md5_context ctx;
     int i;
     unsigned char buf[1000];
+	bool restricted = (length != 0);
+	int readlen;
 
 	f.open(name, File::kFileReadMode, directory);
 	if( ! f.isOpen() )
@@ -253,11 +255,23 @@
 		return false;
 	}
 
+	if( ! restricted || sizeof( buf ) <= length ) 
+		readlen = sizeof( buf );
+	else 
+		readlen = length;
+
 	md5_starts( &ctx );
 
-	while( ( i = f.read( buf, sizeof( buf ) ) ) > 0 )
+	while( ( i = f.read( buf, readlen ) ) > 0 )
 	{
 		md5_update( &ctx, buf, i );
+
+		length -= i;
+		if( restricted && length == 0 )
+			break;
+
+		if( restricted && sizeof( buf ) > length ) 
+			readlen = length;
 	}
 
 	md5_finish( &ctx, digest );

Index: md5.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/common/md5.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- md5.h	29 Jun 2004 12:07:15 -0000	1.4
+++ md5.h	22 Dec 2004 13:34:28 -0000	1.5
@@ -35,6 +35,6 @@
 void md5_update( md5_context *ctx, const uint8 *input, uint32 length );
 void md5_finish( md5_context *ctx, uint8 digest[16] );
 
-bool md5_file( const char *name, uint8 digest[16], const char *directory = NULL );
+bool md5_file( const char *name, uint8 digest[16], const char *directory = NULL, uint32 length = 0 );
 
 #endif





More information about the Scummvm-git-logs mailing list