@@ -828,7 +828,7 @@ std::error_code status(int FD, file_status &Result) {
828828}
829829
830830std::error_code status (file_t FileHandle, file_status &Result) {
831- return getStatus (FileHandle, Result);
831+ return getStatus (FileHandle. get () , Result);
832832}
833833
834834unsigned getUmask () { return 0 ; }
@@ -897,8 +897,8 @@ std::error_code mapped_file_region::init(sys::fs::file_t OrigFileHandle,
897897 break ;
898898 }
899899
900- HANDLE FileMappingHandle = ::CreateFileMappingW (OrigFileHandle, 0 , flprotect,
901- Hi_32 (Size), Lo_32 (Size), 0 );
900+ HANDLE FileMappingHandle = ::CreateFileMappingW (
901+ OrigFileHandle. get (), 0 , flprotect, Hi_32 (Size), Lo_32 (Size), 0 );
902902 if (FileMappingHandle == NULL ) {
903903 std::error_code ec = mapWindowsError (GetLastError ());
904904 return ec;
@@ -942,7 +942,7 @@ std::error_code mapped_file_region::init(sys::fs::file_t OrigFileHandle,
942942 // are closed and the file is deleted, which may cause invalid data to be read
943943 // from the file.
944944 ::CloseHandle (FileMappingHandle);
945- if (!::DuplicateHandle (::GetCurrentProcess (), OrigFileHandle,
945+ if (!::DuplicateHandle (::GetCurrentProcess (), OrigFileHandle. get () ,
946946 ::GetCurrentProcess (), &FileHandle, 0, 0,
947947 DUPLICATE_SAME_ACCESS)) {
948948 std::error_code ec = mapWindowsError (GetLastError ());
@@ -1006,18 +1006,18 @@ void mapped_file_region::unmapImpl() {
10061006 // sure we are on a local file system.
10071007 bool IsLocal = false ;
10081008 SmallVector<wchar_t , 128 > FinalPath;
1009- if (!realPathFromHandle (FileHandle, FinalPath)) {
1009+ if (!realPathFromHandle (FileHandle. get () , FinalPath)) {
10101010 // Not checking the return value here - if the check fails, assume the
10111011 // file isn't local.
10121012 is_local_internal (FinalPath, IsLocal);
10131013 }
10141014 DoFlush = !IsLocal;
10151015 }
10161016 if (DoFlush)
1017- ::FlushFileBuffers (FileHandle);
1017+ ::FlushFileBuffers (FileHandle.get() );
10181018 }
10191019
1020- ::CloseHandle (FileHandle);
1020+ ::CloseHandle (FileHandle.get() );
10211021 }
10221022}
10231023
@@ -1026,7 +1026,7 @@ void mapped_file_region::dontNeedImpl() {}
10261026std::error_code mapped_file_region::sync () const {
10271027 if (!::FlushViewOfFile (Mapping, Size))
10281028 return mapWindowsError (GetLastError ());
1029- if (!::FlushFileBuffers (FileHandle))
1029+ if (!::FlushFileBuffers (FileHandle. get () ))
10301030 return mapWindowsError (GetLastError ());
10311031 return std::error_code ();
10321032}
@@ -1145,7 +1145,7 @@ std::error_code detail::directory_iterator_increment(detail::DirIterState &IT) {
11451145
11461146ErrorOr<basic_file_status> directory_entry::status () const { return Status; }
11471147
1148- static std::error_code nativeFileToFd (Expected<HANDLE > H, int &ResultFD,
1148+ static std::error_code nativeFileToFd (Expected<file_t > H, int &ResultFD,
11491149 OpenFlags Flags) {
11501150 int CrtOpenFlags = 0 ;
11511151 if (Flags & OF_Append)
@@ -1160,9 +1160,9 @@ static std::error_code nativeFileToFd(Expected<HANDLE> H, int &ResultFD,
11601160 if (!H)
11611161 return errorToErrorCode (H.takeError ());
11621162
1163- ResultFD = ::_open_osfhandle (intptr_t (*H ), CrtOpenFlags);
1163+ ResultFD = ::_open_osfhandle (intptr_t (H-> get () ), CrtOpenFlags);
11641164 if (ResultFD == -1 ) {
1165- ::CloseHandle (*H );
1165+ ::CloseHandle (H-> get () );
11661166 return mapWindowsError(ERROR_INVALID_HANDLE);
11671167 }
11681168 return std::error_code ();
@@ -1264,9 +1264,9 @@ Expected<file_t> openNativeFile(const Twine &Name, CreationDisposition Disp,
12641264 SYSTEMTIME SystemTime;
12651265 GetSystemTime (&SystemTime);
12661266 if (SystemTimeToFileTime (&SystemTime, &FileTime) == 0 ||
1267- SetFileTime (Result, NULL , &FileTime, NULL ) == 0 ) {
1267+ SetFileTime (Result. get () , NULL , &FileTime, NULL ) == 0 ) {
12681268 DWORD LastError = ::GetLastError ();
1269- ::CloseHandle (Result);
1269+ ::CloseHandle (Result.get() );
12701270 return errorCodeToError (mapWindowsError (LastError));
12711271 }
12721272 }
@@ -1281,7 +1281,7 @@ std::error_code openFile(const Twine &Name, int &ResultFD,
12811281 if (!Result)
12821282 return errorToErrorCode (Result.takeError ());
12831283
1284- return nativeFileToFd (* Result, ResultFD, Flags);
1284+ return nativeFileToFd (std::move ( Result) , ResultFD, Flags);
12851285}
12861286
12871287static std::error_code directoryRealPath (const Twine &Name,
@@ -1292,15 +1292,15 @@ static std::error_code directoryRealPath(const Twine &Name,
12921292 if (EC)
12931293 return EC;
12941294
1295- EC = realPathFromHandle (File, RealPath);
1296- ::CloseHandle (File);
1295+ EC = realPathFromHandle (File. get () , RealPath);
1296+ ::CloseHandle (File.get() );
12971297 return EC;
12981298}
12991299
13001300std::error_code openFileForRead (const Twine &Name, int &ResultFD,
13011301 OpenFlags Flags,
13021302 SmallVectorImpl<char > *RealPath) {
1303- Expected<HANDLE > NativeFile = openNativeFileForRead (Name, Flags, RealPath);
1303+ Expected<file_t > NativeFile = openNativeFileForRead (Name, Flags, RealPath);
13041304 return nativeFileToFd (std::move (NativeFile), ResultFD, OF_None);
13051305}
13061306
@@ -1311,13 +1311,13 @@ Expected<file_t> openNativeFileForRead(const Twine &Name, OpenFlags Flags,
13111311
13121312 // Fetch the real name of the file, if the user asked
13131313 if (Result && RealPath)
1314- realPathFromHandle (* Result, *RealPath);
1314+ realPathFromHandle (Result-> get () , *RealPath);
13151315
13161316 return Result;
13171317}
13181318
13191319file_t convertFDToNativeFile (int FD) {
1320- return reinterpret_cast <HANDLE>(::_get_osfhandle (FD));
1320+ return file_t ( reinterpret_cast <HANDLE>(::_get_osfhandle (FD) ));
13211321}
13221322
13231323file_t getStdinHandle () { return ::GetStdHandle (STD_INPUT_HANDLE); }
@@ -1332,7 +1332,8 @@ Expected<size_t> readNativeFileImpl(file_t FileHandle,
13321332 DWORD BytesToRead =
13331333 std::min (size_t (std::numeric_limits<DWORD>::max ()), Buf.size ());
13341334 DWORD BytesRead = 0 ;
1335- if (::ReadFile (FileHandle, Buf.data (), BytesToRead, &BytesRead, Overlap))
1335+ if (::ReadFile (FileHandle.get (), Buf.data (), BytesToRead, &BytesRead,
1336+ Overlap))
13361337 return BytesRead;
13371338 DWORD Err = ::GetLastError ();
13381339 // EOF is not an error.
@@ -1363,7 +1364,7 @@ std::error_code tryLockFile(int FD, std::chrono::milliseconds Timeout,
13631364 auto Start = std::chrono::steady_clock::now ();
13641365 auto End = Start + Timeout;
13651366 do {
1366- if (::LockFileEx (File, Flags, 0 , MAXDWORD, MAXDWORD, &OV))
1367+ if (::LockFileEx (File. get () , Flags, 0 , MAXDWORD, MAXDWORD, &OV))
13671368 return std::error_code ();
13681369 DWORD Error = ::GetLastError ();
13691370 if (Error == ERROR_LOCK_VIOLATION) {
@@ -1381,7 +1382,7 @@ std::error_code lockFile(int FD, LockKind Kind) {
13811382 DWORD Flags = Kind == LockKind::Exclusive ? LOCKFILE_EXCLUSIVE_LOCK : 0 ;
13821383 OVERLAPPED OV = {};
13831384 file_t File = convertFDToNativeFile (FD);
1384- if (::LockFileEx (File, Flags, 0 , MAXDWORD, MAXDWORD, &OV))
1385+ if (::LockFileEx (File. get () , Flags, 0 , MAXDWORD, MAXDWORD, &OV))
13851386 return std::error_code ();
13861387 DWORD Error = ::GetLastError ();
13871388 return mapWindowsError (Error);
@@ -1390,15 +1391,15 @@ std::error_code lockFile(int FD, LockKind Kind) {
13901391std::error_code unlockFile (int FD) {
13911392 OVERLAPPED OV = {};
13921393 file_t File = convertFDToNativeFile (FD);
1393- if (::UnlockFileEx (File, 0 , MAXDWORD, MAXDWORD, &OV))
1394+ if (::UnlockFileEx (File. get () , 0 , MAXDWORD, MAXDWORD, &OV))
13941395 return std::error_code ();
13951396 return mapWindowsError (::GetLastError ());
13961397}
13971398
13981399std::error_code closeFile (file_t &F) {
13991400 file_t TmpF = F;
14001401 F = file_t ::Invalid;
1401- if (!::CloseHandle (TmpF))
1402+ if (!::CloseHandle (TmpF. get () ))
14021403 return mapWindowsError (::GetLastError ());
14031404 return std::error_code ();
14041405}
0 commit comments