summaryrefslogtreecommitdiff
path: root/src/qcommon/md5.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/qcommon/md5.c')
-rw-r--r--src/qcommon/md5.c23
1 files changed, 17 insertions, 6 deletions
diff --git a/src/qcommon/md5.c b/src/qcommon/md5.c
index ffe77527..5cf12bb3 100644
--- a/src/qcommon/md5.c
+++ b/src/qcommon/md5.c
@@ -257,20 +257,27 @@ static void MD5Final(struct MD5Context *ctx, unsigned char *digest)
}
-char *Com_MD5File(const char *fn, int length)
+char *Com_MD5File( const char *fn, int length, const char *prefix, int prefix_len )
{
- static char final[33] = {"unknown"};
+ static char final[33] = {""};
unsigned char digest[16] = {""};
fileHandle_t f;
MD5_CTX md5;
- char buffer[2048];
+ byte buffer[2048];
int i;
int filelen = 0;
int r = 0;
int total = 0;
- filelen = FS_FOpenFileRead(fn, &f, qtrue);
- if(filelen < 1) {
+ Q_strncpyz( final, "", sizeof( final ) );
+
+ filelen = FS_SV_FOpenFileRead( fn, &f );
+
+ if( !f ) {
+ return final;
+ }
+ if( filelen < 1 ) {
+ FS_FCloseFile( f );
return final;
}
if(filelen < length || !length) {
@@ -278,6 +285,10 @@ char *Com_MD5File(const char *fn, int length)
}
MD5Init(&md5);
+
+ if( prefix_len && *prefix )
+ MD5Update(&md5 , (unsigned char *)prefix, prefix_len);
+
for(;;) {
r = FS_Read2(buffer, sizeof(buffer), f);
if(r < 1)
@@ -285,7 +296,7 @@ char *Com_MD5File(const char *fn, int length)
if(r + total > length)
r = length - total;
total += r;
- MD5Update(&md5 , (unsigned char *)buffer, r);
+ MD5Update(&md5 , buffer, r);
if(r < sizeof(buffer) || total >= length)
break;
}