[Scummvm-cvs-logs] CVS: scummvm/common md5.cpp,1.4,1.4.2.1 md5.h,1.4,1.4.2.1
Max Horn
fingolfin at users.sourceforge.net
Tue Jan 4 17:29:04 CET 2005
Update of /cvsroot/scummvm/scummvm/common
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3526
Modified Files:
Tag: branch-0-7-0
md5.cpp md5.h
Log Message:
Backport md5_file changes to 0.7.x branch
Index: md5.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/common/md5.cpp,v
retrieving revision 1.4
retrieving revision 1.4.2.1
diff -u -d -r1.4 -r1.4.2.1
--- md5.cpp 29 Jun 2004 12:07:14 -0000 1.4
+++ md5.cpp 5 Jan 2005 01:25:10 -0000 1.4.2.1
@@ -1,5 +1,5 @@
/* ScummVM - Scumm Interpreter
- * Copyright (C) 2002-2004 The ScummVM project
+ * Copyright (C) 2002-2005 The ScummVM project
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -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.4.2.1
diff -u -d -r1.4 -r1.4.2.1
--- md5.h 29 Jun 2004 12:07:15 -0000 1.4
+++ md5.h 5 Jan 2005 01:25:24 -0000 1.4.2.1
@@ -1,5 +1,5 @@
/* ScummVM - Scumm Interpreter
- * Copyright (C) 2002-2004 The ScummVM project
+ * Copyright (C) 2002-2005 The ScummVM project
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -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