Skip to content

Commit cc35672

Browse files
committed
(#7798) [vcpkg] Fix the build on FreeBSD 😈
Add a `#else` line to `toolsrc/src/vcpkg/base/files.cpp`. On Linux and macOS, there are specific ways to copy from file descriptor to file descriptor, but on FreeBSD there isn't (as far as I could tell). This change does a copy using the POSIX standard `read` and `write` calls. (This change was to `RealFilesystem::rename_or_copy`). We expect to have people on FreeBSD install CMake themselves, and use `./bootstrap.sh -useSystemBinaries`, in order to build vcpkg. Since CMake 3.15.2 exists in the FreeBSD 12 (latest stable) package manager, it's trivial to install it.
1 parent 78abf65 commit cc35672

File tree

1 file changed

+29
-3
lines changed

1 file changed

+29
-3
lines changed

‎toolsrc/src/vcpkg/base/files.cpp‎

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@
88
#include <vcpkg/base/util.h>
99
#include <vcpkg/base/work_queue.h>
1010

11-
#if defined(__linux__) || defined(__APPLE__)
11+
#if !defined(_WIN32)
1212
#include <fcntl.h>
13-
#include <string.h>
1413
#include <sys/stat.h>
1514
#include <sys/types.h>
1615
#include <unistd.h>
@@ -396,7 +395,7 @@ namespace vcpkg::Files
396395
{
397396
this->rename(oldpath, newpath, ec);
398397
Util::unused(temp_suffix);
399-
#if defined(__linux__) || defined(__APPLE__)
398+
#if !defined(_WIN32)
400399
if (ec)
401400
{
402401
auto dst = newpath;
@@ -419,6 +418,33 @@ namespace vcpkg::Files
419418
auto written_bytes = sendfile(o_fd, i_fd, &bytes, info.st_size);
420419
#elif defined(__APPLE__)
421420
auto written_bytes = fcopyfile(i_fd, o_fd, 0, COPYFILE_ALL);
421+
#else
422+
ssize_t written_bytes = 0;
423+
{
424+
constexpr std::size_t buffer_length = 4096;
425+
auto buffer = std::make_unique<unsigned char[]>(buffer_length);
426+
while (auto read_bytes = read(i_fd, buffer.get(), buffer_length))
427+
{
428+
if (read_bytes == -1)
429+
{
430+
written_bytes = -1;
431+
break;
432+
}
433+
auto remaining = read_bytes;
434+
while (remaining > 0) {
435+
auto read_result = write(o_fd, buffer.get(), remaining);
436+
if (read_result == -1)
437+
{
438+
written_bytes = -1;
439+
// break two loops
440+
goto copy_failure;
441+
}
442+
remaining -= read_result;
443+
}
444+
}
445+
446+
copy_failure: ;
447+
}
422448
#endif
423449
if (written_bytes == -1)
424450
{

0 commit comments

Comments
 (0)