Make "Crypto" file opening unicode-safe on Windows.

This commit is contained in:
Jordan Woyak 2013-03-03 19:14:13 -06:00
parent 6b2818199c
commit 989f0663eb
2 changed files with 12 additions and 6 deletions

View File

@ -37,6 +37,8 @@
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>
#include "FileUtil.h"
/* /*
* 32-bit integer manipulation macros (little endian) * 32-bit integer manipulation macros (little endian)
*/ */
@ -301,7 +303,10 @@ int md5_file( char *path, unsigned char output[16] )
md5_context ctx; md5_context ctx;
unsigned char buf[1024]; unsigned char buf[1024];
if( ( f = fopen( path, "rb" ) ) == NULL ) File::IOFile file(path, "rb");
f = file.GetHandle();
if (f == NULL)
return( 1 ); return( 1 );
md5_starts( &ctx ); md5_starts( &ctx );
@ -315,11 +320,9 @@ int md5_file( char *path, unsigned char output[16] )
if( ferror( f ) != 0 ) if( ferror( f ) != 0 )
{ {
fclose( f );
return( 2 ); return( 2 );
} }
fclose( f );
return( 0 ); return( 0 );
} }

View File

@ -36,6 +36,8 @@
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>
#include "FileUtil.h"
/* /*
* 32-bit integer manipulation macros (big endian) * 32-bit integer manipulation macros (big endian)
*/ */
@ -335,7 +337,10 @@ int sha1_file( char *path, unsigned char output[20] )
sha1_context ctx; sha1_context ctx;
unsigned char buf[1024]; unsigned char buf[1024];
if( ( f = fopen( path, "rb" ) ) == NULL ) File::IOFile file(path, "rb");
f = file.GetHandle();
if (f == NULL)
return( 1 ); return( 1 );
sha1_starts( &ctx ); sha1_starts( &ctx );
@ -349,11 +354,9 @@ int sha1_file( char *path, unsigned char output[20] )
if( ferror( f ) != 0 ) if( ferror( f ) != 0 )
{ {
fclose( f );
return( 2 ); return( 2 );
} }
fclose( f );
return( 0 ); return( 0 );
} }