return wrapvFull(readv, fd, iov, count);
}
+#ifdef FOLLY_HAVE_PREADV
ssize_t preadvFull(int fd, iovec* iov, int count, off_t offset) {
return wrapvFull(preadv, fd, iov, count, offset);
}
+#endif
ssize_t writevFull(int fd, iovec* iov, int count) {
return wrapvFull(writev, fd, iov, count);
}
+#ifdef FOLLY_HAVE_PWRITEV
ssize_t pwritevFull(int fd, iovec* iov, int count, off_t offset) {
return wrapvFull(pwritev, fd, iov, count, offset);
}
+#endif
} // namespaces
#ifndef FOLLY_FILEUTIL_H_
#define FOLLY_FILEUTIL_H_
+#include "folly/Portability.h"
+
#include <sys/uio.h>
#include <unistd.h>
ssize_t readFull(int fd, void* buf, size_t n);
ssize_t preadFull(int fd, void* buf, size_t n, off_t offset);
ssize_t readvFull(int fd, iovec* iov, int count);
+#ifdef FOLLY_HAVE_PREADV
ssize_t preadvFull(int fd, iovec* iov, int count, off_t offset);
+#endif
/**
* Similar to readFull and preadFull above, wrappers around write() and
ssize_t writeFull(int fd, const void* buf, size_t n);
ssize_t pwriteFull(int fd, const void* buf, size_t n, off_t offset);
ssize_t writevFull(int fd, iovec* iov, int count);
+#ifdef FOLLY_HAVE_PWRITEV
ssize_t pwritevFull(int fd, iovec* iov, int count, off_t offset);
+#endif
} // namespaces
#pragma GCC system_header
#define FOLLY_HAVE_MALLOC_H 1
#else
-#include "folly-config.h"
+#include "folly/Portability.h"
#endif
// for malloc_usable_size
#include "folly-config.h"
+#ifdef FOLLY_HAVE_FEATURES_H
+#include <features.h>
+#endif
+
+
#ifdef FOLLY_HAVE_SCHED_H
#include <sched.h>
#ifndef FOLLY_HAVE_PTHREAD_YIELD
# error Cannot define MaxAlign on this platform
#endif
+
+// noreturn
#if defined(__clang__) || defined(__GNUC__)
# define FOLLY_NORETURN __attribute__((noreturn))
#else
# define FOLLY_NORETURN
#endif
+
+/* Define macro wrappers for C++11's "final" and "override" keywords, which
+ * are supported in gcc 4.7 but not gcc 4.6. */
+#if !defined(FOLLY_FINAL) && !defined(FOLLY_OVERRIDE)
+# if defined(__clang__) || \
+ (defined(__GNUC__) && defined(__GNUC_MINOR__) && \
+ ((__GNUC__ << 16) + __GNUC_MINOR__) >= ((4 << 16) + 7))
+# define FOLLY_FINAL final
+# define FOLLY_OVERRIDE override
+# else
+# define FOLLY_FINAL /**/
+# define FOLLY_OVERRIDE /**/
+# endif
+#endif
+
+
+// Define to 1 if you have the `preadv' and `pwritev' functions, respectively
+#if !defined(FOLLY_HAVE_PREADV) && !defined(FOLLY_HAVE_PWRITEV)
+# if defined(__GLIBC_PREREQ) && __GLIBC_PREREQ(2, 10)
+# define FOLLY_HAVE_PREADV 1
+# define FOLLY_HAVE_PWRITEV 1
+# endif
+#endif
+
#endif // FOLLY_PORTABILITY_H_
#ifndef FOLLY_RANGE_H_
#define FOLLY_RANGE_H_
-#include "folly/folly-config.h"
+#include "folly/Portability.h"
#include "folly/FBString.h"
#include <glog/logging.h>
#include <algorithm>
# Checks for header files.
AC_HEADER_STDC
-AC_CHECK_HEADERS([fcntl.h inttypes.h limits.h stdint.h stdlib.h string.h sys/time.h unistd.h mutex.h malloc.h emmintrin.h byteswap.h])
+AC_CHECK_HEADERS([fcntl.h features.h inttypes.h limits.h stdint.h stdlib.h string.h sys/time.h unistd.h mutex.h malloc.h emmintrin.h byteswap.h])
AC_CHECK_HEADER(double-conversion.h, [], [AC_MSG_ERROR(
[Couldn't find double-conversion.h, please download from \
#include "folly/Exception.h"
#include "folly/FileUtil.h"
#include "folly/Memory.h"
+#include "folly/Portability.h"
#include "folly/ScopeGuard.h"
#include "folly/String.h"
}
DCHECK_EQ(buf->computeChainDataLength(), totalLength);
- auto iov = buf->getIov();
// We're going to write. Reserve space for ourselves.
off_t pos = filePos_.fetch_add(totalLength);
+
+#ifdef FOLLY_HAVE_PWRITEV
+ auto iov = buf->getIov();
ssize_t bytes = pwritevFull(file_.fd(), iov.data(), iov.size(), pos);
+#else
+ buf->unshare();
+ buf->coalesce();
+ ssize_t bytes = pwriteFull(file_.fd(), buf->data(), buf->length(), pos);
+#endif
+
checkUnixError(bytes, "pwrite() failed");
DCHECK_EQ(bytes, totalLength);
}
}
}
+#ifdef FOLLY_HAVE_PREADV
TEST_F(FileUtilTest, preadv) {
for (auto& p : readers_) {
IovecBuffers buf({12, 19, 31});
}
}
}
+#endif
}} // namespaces