From 989f0663eb212164e11e80626fa89900d2f1ae3e Mon Sep 17 00:00:00 2001 From: Jordan Woyak Date: Sun, 3 Mar 2013 19:14:13 -0600 Subject: [PATCH] Make "Crypto" file opening unicode-safe on Windows. --- Source/Core/Common/Src/Crypto/md5.cpp | 9 ++++++--- Source/Core/Common/Src/Crypto/sha1.cpp | 9 ++++++--- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/Source/Core/Common/Src/Crypto/md5.cpp b/Source/Core/Common/Src/Crypto/md5.cpp index 7fff7713da..ef31636aea 100644 --- a/Source/Core/Common/Src/Crypto/md5.cpp +++ b/Source/Core/Common/Src/Crypto/md5.cpp @@ -37,6 +37,8 @@ #include #include +#include "FileUtil.h" + /* * 32-bit integer manipulation macros (little endian) */ @@ -301,7 +303,10 @@ int md5_file( char *path, unsigned char output[16] ) md5_context ctx; unsigned char buf[1024]; - if( ( f = fopen( path, "rb" ) ) == NULL ) + File::IOFile file(path, "rb"); + f = file.GetHandle(); + + if (f == NULL) return( 1 ); md5_starts( &ctx ); @@ -315,11 +320,9 @@ int md5_file( char *path, unsigned char output[16] ) if( ferror( f ) != 0 ) { - fclose( f ); return( 2 ); } - fclose( f ); return( 0 ); } diff --git a/Source/Core/Common/Src/Crypto/sha1.cpp b/Source/Core/Common/Src/Crypto/sha1.cpp index 17ad930986..3d26dc8a50 100644 --- a/Source/Core/Common/Src/Crypto/sha1.cpp +++ b/Source/Core/Common/Src/Crypto/sha1.cpp @@ -36,6 +36,8 @@ #include #include +#include "FileUtil.h" + /* * 32-bit integer manipulation macros (big endian) */ @@ -335,7 +337,10 @@ int sha1_file( char *path, unsigned char output[20] ) sha1_context ctx; unsigned char buf[1024]; - if( ( f = fopen( path, "rb" ) ) == NULL ) + File::IOFile file(path, "rb"); + f = file.GetHandle(); + + if (f == NULL) return( 1 ); sha1_starts( &ctx ); @@ -349,11 +354,9 @@ int sha1_file( char *path, unsigned char output[20] ) if( ferror( f ) != 0 ) { - fclose( f ); return( 2 ); } - fclose( f ); return( 0 ); }