Commit eaf22e04 authored by Matt Galloway's avatar Matt Galloway Committed by Facebook GitHub Bot

folly | Fix building folly's FileUtil.cpp in iOS 14 or macOS 11 SDK

Summary: Fix issue where `preadv` and `pwritev` are now included in iOS 14 and macOS 11 SDKs, so we need to do runtime checks for those platforms.

Reviewed By: Orvid

Differential Revision: D22275221

fbshipit-source-id: 12e45c55a0fcf10f540f2d4cb9a3c392d7e182cb
parent e4869845
......@@ -48,17 +48,57 @@ static int wrapPositional(F f, int fd, off_t offset, Args... args) {
return res;
}
namespace {
#if !FOLLY_HAVE_PREADV
extern "C" ssize_t preadv(int fd, const iovec* iov, int count, off_t offset) {
return wrapPositional(readv, fd, offset, iov, count);
ssize_t preadv_fallback(int fd, const iovec* iov, int count, off_t offset) {
return static_cast<ssize_t>(wrapPositional(readv, fd, offset, iov, count));
}
#endif
#if !FOLLY_HAVE_PWRITEV
extern "C" ssize_t pwritev(int fd, const iovec* iov, int count, off_t offset) {
return wrapPositional(writev, fd, offset, iov, count);
ssize_t pwritev_fallback(int fd, const iovec* iov, int count, off_t offset) {
return static_cast<ssize_t>(wrapPositional(writev, fd, offset, iov, count));
}
#endif
} // namespace
namespace folly {
#if !FOLLY_HAVE_PREADV
ssize_t preadv(int fd, const iovec* iov, int count, off_t offset) {
using sig = ssize_t(int, const iovec*, int, off_t);
static auto the_preadv = []() -> sig* {
#if defined(__APPLE__) && FOLLY_HAS_BUILTIN(__builtin_available) && \
(__MAC_OS_X_VERSION_MAX_ALLOWED >= 101600 || \
__IPHONE_OS_VERSION_MAX_ALLOWED >= 140000)
if (__builtin_available(iOS 14.0, macOS 11.0, *)) {
return &::preadv;
}
#endif
return &preadv_fallback;
}();
return the_preadv(fd, iov, count, offset);
}
#endif
#if !FOLLY_HAVE_PWRITEV
ssize_t pwritev(int fd, const iovec* iov, int count, off_t offset) {
using sig = ssize_t(int, const iovec*, int, off_t);
static auto the_pwritev = []() -> sig* {
#if defined(__APPLE__) && FOLLY_HAS_BUILTIN(__builtin_available) && \
(__MAC_OS_X_VERSION_MAX_ALLOWED >= 101600 || \
__IPHONE_OS_VERSION_MAX_ALLOWED >= 140000)
if (__builtin_available(iOS 14.0, macOS 11.0, *)) {
return &::pwritev;
}
#endif
return &pwritev_fallback;
}();
return the_pwritev(fd, iov, count, offset);
}
#endif
} // namespace folly
#ifdef _WIN32
template <bool isRead>
......
......@@ -20,12 +20,22 @@
#include <folly/portability/IOVec.h>
#include <folly/portability/SysTypes.h>
#if FOLLY_HAVE_PREADV || FOLLY_HAVE_PWRITEV
#include <sys/uio.h>
#endif
namespace folly {
#if !FOLLY_HAVE_PREADV
extern "C" ssize_t preadv(int fd, const iovec* iov, int count, off_t offset);
ssize_t preadv(int fd, const iovec* iov, int count, off_t offset);
#else
using ::preadv;
#endif
#if !FOLLY_HAVE_PWRITEV
extern "C" ssize_t pwritev(int fd, const iovec* iov, int count, off_t offset);
ssize_t pwritev(int fd, const iovec* iov, int count, off_t offset);
#else
using ::pwritev;
#endif
} // namespace folly
#ifdef _WIN32
extern "C" ssize_t readv(int fd, const iovec* iov, int count);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment