@@ -913,26 +913,6 @@ std::wstring StringToWString(const std::string& str)
913
913
return converterX.from_bytes (str);
914
914
}
915
915
916
- class ReadFileHandle {
917
- HANDLE hFile;
918
- public:
919
- ReadFileHandle (const std::wstring& filename) {
920
- hFile = CreateFile (filename.c_str (), GENERIC_READ,
921
- FILE_SHARE_READ, NULL , OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );
922
- if (INVALID_HANDLE_VALUE == hFile)
923
- throw " Could not initialize read handle" ;
924
- }
925
- ~ReadFileHandle () {
926
- if (hFile)
927
- CloseHandle (hFile);
928
- }
929
- operator HANDLE () {
930
- return hFile;
931
- }
932
- };
933
-
934
-
935
-
936
916
int32 ReadFile (ExtensionString filename, ExtensionString& encoding, std::string& contents, bool & preserveBOM)
937
917
{
938
918
if (encoding == L" utf8" ) {
@@ -946,10 +926,13 @@ int32 ReadFile(ExtensionString filename, ExtensionString& encoding, std::string&
946
926
if (dwAttr & FILE_ATTRIBUTE_DIRECTORY)
947
927
return ERR_CANT_READ;
948
928
949
- ReadFileHandle readFileHandle (filename);
950
- HANDLE hFile = readFileHandle ;
929
+ HANDLE hFile = CreateFile (filename. c_str (), GENERIC_READ,
930
+ FILE_SHARE_READ, NULL , OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL ) ;
951
931
int32 error = NO_ERROR;
952
932
933
+ if (INVALID_HANDLE_VALUE == hFile)
934
+ return ConvertWinErrorCode (GetLastError ());
935
+
953
936
DWORD dwFileSize = GetFileSize (hFile, NULL );
954
937
955
938
if (dwFileSize == 0 ) {
@@ -1027,6 +1010,7 @@ int32 ReadFile(ExtensionString filename, ExtensionString& encoding, std::string&
1027
1010
}
1028
1011
}
1029
1012
}
1013
+ CloseHandle (hFile);
1030
1014
return error;
1031
1015
}
1032
1016
0 commit comments