Skip to content

Commit

Permalink
Fixed build
Browse files Browse the repository at this point in the history
  • Loading branch information
deathkiller committed Nov 23, 2023
1 parent 57a2b7b commit 3e762f1
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions Sources/Shared/IO/FileSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1661,18 +1661,23 @@ namespace Death::IO
return false;
}
::fstat(source, &sb);
# if defined(DEATH_TARGET_SWITCH)
// Switch doesn't support `creat()`
if ((dest = ::open(nullTerminatedNewPath.data(), O_WRONLY | O_CREAT, sb.st_mode)) == -1) {
# else
if ((dest = ::creat(nullTerminatedNewPath.data(), sb.st_mode)) == -1) {
# endif
::close(source);
return false;
}

#if defined(DEATH_TARGET_APPLE) || defined(__FreeBSD__)
# if defined(DEATH_TARGET_APPLE) || defined(__FreeBSD__)
// fcopyfile works on FreeBSD and OS X 10.5+
bool success = (::fcopyfile(source, dest, 0, COPYFILE_ALL) == 0);
#elif defined(__linux__)
# elif defined(__linux__)
off_t offset = 0;
bool success = (::sendfile(dest, source, &offset, sb.st_size) == sb.st_size);
#else
# else
# if !defined(DEATH_TARGET_SWITCH) && defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 200112L
// As noted in https://eklitzke.org/efficient-file-copying-on-linux, might make the file reading faster
::posix_fadvise(source, 0, 0, POSIX_FADV_SEQUENTIAL);
Expand Down

0 comments on commit 3e762f1

Please sign in to comment.