@@ -357,7 +357,7 @@ uint32_t file_status::getLinkCount() const { return fs_st_nlinks; }
357
357
ErrorOr<space_info> disk_space (const Twine &Path) {
358
358
struct STATVFS Vfs;
359
359
if (::STATVFS (const_cast <char *>(Path.str ().c_str ()), &Vfs))
360
- return std::error_code (errno, std::generic_category () );
360
+ return errnoAsErrorCode ( );
361
361
auto FrSize = STATVFS_F_FRSIZE (Vfs);
362
362
space_info SpaceInfo;
363
363
SpaceInfo.capacity = static_cast <uint64_t >(Vfs.f_blocks ) * FrSize;
@@ -386,7 +386,7 @@ std::error_code current_path(SmallVectorImpl<char> &result) {
386
386
// See if there was a real error.
387
387
if (errno != ENOMEM) {
388
388
result.clear ();
389
- return std::error_code (errno, std::generic_category () );
389
+ return errnoAsErrorCode ( );
390
390
}
391
391
// Otherwise there just wasn't enough space.
392
392
result.resize_for_overwrite (result.capacity () * 2 );
@@ -403,7 +403,7 @@ std::error_code set_current_path(const Twine &path) {
403
403
StringRef p = path.toNullTerminatedStringRef (path_storage);
404
404
405
405
if (::chdir (p.begin ()) == -1 )
406
- return std::error_code (errno, std::generic_category () );
406
+ return errnoAsErrorCode ( );
407
407
408
408
return std::error_code ();
409
409
}
@@ -415,7 +415,7 @@ std::error_code create_directory(const Twine &path, bool IgnoreExisting,
415
415
416
416
if (::mkdir (p.begin (), Perms) == -1 ) {
417
417
if (errno != EEXIST || !IgnoreExisting)
418
- return std::error_code (errno, std::generic_category () );
418
+ return errnoAsErrorCode ( );
419
419
}
420
420
421
421
return std::error_code ();
@@ -431,7 +431,7 @@ std::error_code create_link(const Twine &to, const Twine &from) {
431
431
StringRef t = to.toNullTerminatedStringRef (to_storage);
432
432
433
433
if (::symlink (t.begin (), f.begin ()) == -1 )
434
- return std::error_code (errno, std::generic_category () );
434
+ return errnoAsErrorCode ( );
435
435
436
436
return std::error_code ();
437
437
}
@@ -444,7 +444,7 @@ std::error_code create_hard_link(const Twine &to, const Twine &from) {
444
444
StringRef t = to.toNullTerminatedStringRef (to_storage);
445
445
446
446
if (::link (t.begin (), f.begin ()) == -1 )
447
- return std::error_code (errno, std::generic_category () );
447
+ return errnoAsErrorCode ( );
448
448
449
449
return std::error_code ();
450
450
}
@@ -456,7 +456,7 @@ std::error_code remove(const Twine &path, bool IgnoreNonExisting) {
456
456
struct stat buf;
457
457
if (lstat (p.begin (), &buf) != 0 ) {
458
458
if (errno != ENOENT || !IgnoreNonExisting)
459
- return std::error_code (errno, std::generic_category () );
459
+ return errnoAsErrorCode ( );
460
460
return std::error_code ();
461
461
}
462
462
@@ -470,7 +470,7 @@ std::error_code remove(const Twine &path, bool IgnoreNonExisting) {
470
470
471
471
if (::remove (p.begin ()) == -1 ) {
472
472
if (errno != ENOENT || !IgnoreNonExisting)
473
- return std::error_code (errno, std::generic_category () );
473
+ return errnoAsErrorCode ( );
474
474
}
475
475
476
476
return std::error_code ();
@@ -563,7 +563,7 @@ static bool is_local_impl(struct STATVFS &Vfs) {
563
563
std::error_code is_local (const Twine &Path, bool &Result) {
564
564
struct STATVFS Vfs;
565
565
if (::STATVFS (const_cast <char *>(Path.str ().c_str ()), &Vfs))
566
- return std::error_code (errno, std::generic_category () );
566
+ return errnoAsErrorCode ( );
567
567
568
568
Result = is_local_impl (Vfs);
569
569
return std::error_code ();
@@ -572,7 +572,7 @@ std::error_code is_local(const Twine &Path, bool &Result) {
572
572
std::error_code is_local (int FD, bool &Result) {
573
573
struct STATVFS Vfs;
574
574
if (::FSTATVFS (FD, &Vfs))
575
- return std::error_code (errno, std::generic_category () );
575
+ return errnoAsErrorCode ( );
576
576
577
577
Result = is_local_impl (Vfs);
578
578
return std::error_code ();
@@ -586,7 +586,7 @@ std::error_code rename(const Twine &from, const Twine &to) {
586
586
StringRef t = to.toNullTerminatedStringRef (to_storage);
587
587
588
588
if (::rename (f.begin (), t.begin ()) == -1 )
589
- return std::error_code (errno, std::generic_category () );
589
+ return errnoAsErrorCode ( );
590
590
591
591
return std::error_code ();
592
592
}
@@ -595,7 +595,7 @@ std::error_code resize_file(int FD, uint64_t Size) {
595
595
// Use ftruncate as a fallback. It may or may not allocate space. At least on
596
596
// OS X with HFS+ it does.
597
597
if (::ftruncate (FD, Size ) == -1 )
598
- return std::error_code (errno, std::generic_category () );
598
+ return errnoAsErrorCode ( );
599
599
600
600
return std::error_code ();
601
601
}
@@ -617,7 +617,7 @@ std::error_code access(const Twine &Path, AccessMode Mode) {
617
617
StringRef P = Path.toNullTerminatedStringRef (PathStorage);
618
618
619
619
if (::access (P.begin (), convertAccessMode (Mode)) == -1 )
620
- return std::error_code (errno, std::generic_category () );
620
+ return errnoAsErrorCode ( );
621
621
622
622
if (Mode == AccessMode::Execute) {
623
623
// Don't say that directories are executable.
@@ -726,7 +726,7 @@ static file_type typeForMode(mode_t Mode) {
726
726
static std::error_code fillStatus (int StatRet, const struct stat &Status,
727
727
file_status &Result) {
728
728
if (StatRet != 0 ) {
729
- std::error_code EC (errno, std::generic_category () );
729
+ std::error_code EC = errnoAsErrorCode ( );
730
730
if (EC == errc::no_such_file_or_directory)
731
731
Result = file_status (file_type::file_not_found);
732
732
else
@@ -782,13 +782,13 @@ std::error_code setPermissions(const Twine &Path, perms Permissions) {
782
782
StringRef P = Path.toNullTerminatedStringRef (PathStorage);
783
783
784
784
if (::chmod (P.begin (), Permissions))
785
- return std::error_code (errno, std::generic_category () );
785
+ return errnoAsErrorCode ( );
786
786
return std::error_code ();
787
787
}
788
788
789
789
std::error_code setPermissions (int FD, perms Permissions) {
790
790
if (::fchmod (FD, Permissions))
791
- return std::error_code (errno, std::generic_category () );
791
+ return errnoAsErrorCode ( );
792
792
return std::error_code ();
793
793
}
794
794
@@ -799,7 +799,7 @@ std::error_code setLastAccessAndModificationTime(int FD, TimePoint<> AccessTime,
799
799
Times[0 ] = sys::toTimeSpec (AccessTime);
800
800
Times[1 ] = sys::toTimeSpec (ModificationTime);
801
801
if (::futimens (FD, Times))
802
- return std::error_code (errno, std::generic_category () );
802
+ return errnoAsErrorCode ( );
803
803
return std::error_code ();
804
804
#elif defined(HAVE_FUTIMES)
805
805
timeval Times[2 ];
@@ -809,7 +809,7 @@ std::error_code setLastAccessAndModificationTime(int FD, TimePoint<> AccessTime,
809
809
sys::toTimeVal (std::chrono::time_point_cast<std::chrono::microseconds>(
810
810
ModificationTime));
811
811
if (::futimes (FD, Times))
812
- return std::error_code (errno, std::generic_category () );
812
+ return errnoAsErrorCode ( );
813
813
return std::error_code ();
814
814
#elif defined(__MVS__)
815
815
attrib_t Attr;
@@ -819,7 +819,7 @@ std::error_code setLastAccessAndModificationTime(int FD, TimePoint<> AccessTime,
819
819
Attr.att_mtimechg = 1 ;
820
820
Attr.att_mtime = sys::toTimeT (ModificationTime);
821
821
if (::__fchattr (FD, &Attr, sizeof (Attr)) != 0 )
822
- return std::error_code (errno, std::generic_category () );
822
+ return errnoAsErrorCode ( );
823
823
return std::error_code ();
824
824
#else
825
825
#warning Missing futimes() and futimens()
@@ -858,7 +858,7 @@ std::error_code mapped_file_region::init(int FD, uint64_t Offset,
858
858
859
859
Mapping = ::mmap (nullptr , Size , prot, flags, FD, Offset);
860
860
if (Mapping == MAP_FAILED)
861
- return std::error_code (errno, std::generic_category () );
861
+ return errnoAsErrorCode ( );
862
862
return std::error_code ();
863
863
}
864
864
@@ -897,7 +897,7 @@ std::error_code detail::directory_iterator_construct(detail::DirIterState &it,
897
897
SmallString<128 > path_null (path);
898
898
DIR *directory = ::opendir (path_null.c_str ());
899
899
if (!directory)
900
- return std::error_code (errno, std::generic_category () );
900
+ return errnoAsErrorCode ( );
901
901
902
902
it.IterationHandle = reinterpret_cast <intptr_t >(directory);
903
903
// Add something for replace_filename to replace.
@@ -932,7 +932,7 @@ std::error_code detail::directory_iterator_increment(detail::DirIterState &It) {
932
932
errno = 0 ;
933
933
dirent *CurDir = ::readdir (reinterpret_cast <DIR *>(It.IterationHandle ));
934
934
if (CurDir == nullptr && errno != 0 ) {
935
- return std::error_code (errno, std::generic_category () );
935
+ return errnoAsErrorCode ( );
936
936
} else if (CurDir != nullptr ) {
937
937
StringRef Name (CurDir->d_name );
938
938
if ((Name.size () == 1 && Name[0 ] == ' .' ) ||
@@ -1023,7 +1023,7 @@ std::error_code openFile(const Twine &Name, int &ResultFD,
1023
1023
// when open is overloaded, such as in Bionic.
1024
1024
auto Open = [&]() { return ::open (P.begin (), OpenFlags, Mode); };
1025
1025
if ((ResultFD = sys::RetryAfterSignal (-1 , Open)) < 0 )
1026
- return std::error_code (errno, std::generic_category () );
1026
+ return errnoAsErrorCode ( );
1027
1027
#ifndef O_CLOEXEC
1028
1028
if (!(Flags & OF_ChildInherit)) {
1029
1029
int r = fcntl (ResultFD, F_SETFD, FD_CLOEXEC);
@@ -1087,10 +1087,10 @@ std::error_code openFile(const Twine &Name, int &ResultFD,
1087
1087
* open().
1088
1088
*/
1089
1089
if ((Flags & OF_Append) && lseek (ResultFD, 0 , SEEK_END) == -1 )
1090
- return std::error_code (errno, std::generic_category () );
1090
+ return errnoAsErrorCode ( );
1091
1091
struct stat Stat;
1092
1092
if (fstat (ResultFD, &Stat) == -1 )
1093
- return std::error_code (errno, std::generic_category () );
1093
+ return errnoAsErrorCode ( );
1094
1094
if (S_ISREG (Stat.st_mode )) {
1095
1095
bool DoSetTag = (Access & FA_Write) && (Disp != CD_OpenExisting) &&
1096
1096
!Stat.st_tag .ft_txtflag && !Stat.st_tag .ft_ccsid &&
@@ -1190,7 +1190,7 @@ Expected<size_t> readNativeFile(file_t FD, MutableArrayRef<char> Buf) {
1190
1190
#endif
1191
1191
ssize_t NumRead = sys::RetryAfterSignal (-1 , ::read , FD, Buf.data (), Size );
1192
1192
if (ssize_t (NumRead) == -1 )
1193
- return errorCodeToError (std::error_code (errno, std::generic_category () ));
1193
+ return errorCodeToError (errnoAsErrorCode ( ));
1194
1194
return NumRead;
1195
1195
}
1196
1196
@@ -1206,11 +1206,11 @@ Expected<size_t> readNativeFileSlice(file_t FD, MutableArrayRef<char> Buf,
1206
1206
sys::RetryAfterSignal (-1 , ::pread , FD, Buf.data (), Size , Offset);
1207
1207
#else
1208
1208
if (lseek (FD, Offset, SEEK_SET) == -1 )
1209
- return errorCodeToError (std::error_code (errno, std::generic_category () ));
1209
+ return errorCodeToError (errnoAsErrorCode ( ));
1210
1210
ssize_t NumRead = sys::RetryAfterSignal (-1 , ::read , FD, Buf.data (), Size );
1211
1211
#endif
1212
1212
if (NumRead == -1 )
1213
- return errorCodeToError (std::error_code (errno, std::generic_category () ));
1213
+ return errorCodeToError (errnoAsErrorCode ( ));
1214
1214
return NumRead;
1215
1215
}
1216
1216
@@ -1243,8 +1243,7 @@ std::error_code lockFile(int FD) {
1243
1243
Lock.l_len = 0 ;
1244
1244
if (::fcntl (FD, F_SETLKW, &Lock) != -1 )
1245
1245
return std::error_code ();
1246
- int Error = errno;
1247
- return std::error_code (Error, std::generic_category ());
1246
+ return errnoAsErrorCode ();
1248
1247
}
1249
1248
1250
1249
std::error_code unlockFile (int FD) {
@@ -1255,7 +1254,7 @@ std::error_code unlockFile(int FD) {
1255
1254
Lock.l_len = 0 ;
1256
1255
if (::fcntl (FD, F_SETLK, &Lock) != -1 )
1257
1256
return std::error_code ();
1258
- return std::error_code (errno, std::generic_category () );
1257
+ return errnoAsErrorCode ( );
1259
1258
}
1260
1259
1261
1260
std::error_code closeFile (file_t &F) {
@@ -1321,7 +1320,7 @@ std::error_code real_path(const Twine &path, SmallVectorImpl<char> &dest,
1321
1320
StringRef P = path.toNullTerminatedStringRef (Storage);
1322
1321
char Buffer[PATH_MAX];
1323
1322
if (::realpath (P.begin (), Buffer) == nullptr )
1324
- return std::error_code (errno, std::generic_category () );
1323
+ return errnoAsErrorCode ( );
1325
1324
dest.append (Buffer, Buffer + strlen (Buffer));
1326
1325
return std::error_code ();
1327
1326
}
@@ -1330,7 +1329,7 @@ std::error_code changeFileOwnership(int FD, uint32_t Owner, uint32_t Group) {
1330
1329
auto FChown = [&]() { return ::fchown (FD, Owner, Group); };
1331
1330
// Retry if fchown call fails due to interruption.
1332
1331
if ((sys::RetryAfterSignal (-1 , FChown)) < 0 )
1333
- return std::error_code (errno, std::generic_category () );
1332
+ return errnoAsErrorCode ( );
1334
1333
return std::error_code ();
1335
1334
}
1336
1335
@@ -1513,7 +1512,7 @@ std::error_code copy_file(const Twine &From, const Twine &To) {
1513
1512
#endif
1514
1513
if (!copyfile (FromS.c_str (), ToS.c_str (), /* State=*/ NULL , COPYFILE_DATA))
1515
1514
return std::error_code ();
1516
- return std::error_code (errno, std::generic_category () );
1515
+ return errnoAsErrorCode ( );
1517
1516
}
1518
1517
#endif // __APPLE__
1519
1518
0 commit comments