Commit 9cdd19b7 authored by Tudor Bosman's avatar Tudor Bosman Committed by Sara Golemon

Unbreak build on glibc 2.5.1

Summary:
Also move manually-generated stuff away from folly-config.h and into
Portability.h.  This should be only for things that differs between the
various (compiler, library) pairs used internally at FB; everything else
should be autoconf-ed and therefore go into folly-config.h.

Test Plan: built and ran file_util_test on various platforms

Reviewed By: delong.j@fb.com

FB internal diff: D807067

Blame Revision: D806781
parent 531568a6
...@@ -85,17 +85,21 @@ ssize_t readvFull(int fd, iovec* iov, int count) { ...@@ -85,17 +85,21 @@ ssize_t readvFull(int fd, iovec* iov, int count) {
return wrapvFull(readv, fd, iov, count); return wrapvFull(readv, fd, iov, count);
} }
#ifdef FOLLY_HAVE_PREADV
ssize_t preadvFull(int fd, iovec* iov, int count, off_t offset) { ssize_t preadvFull(int fd, iovec* iov, int count, off_t offset) {
return wrapvFull(preadv, fd, iov, count, offset); return wrapvFull(preadv, fd, iov, count, offset);
} }
#endif
ssize_t writevFull(int fd, iovec* iov, int count) { ssize_t writevFull(int fd, iovec* iov, int count) {
return wrapvFull(writev, fd, iov, count); return wrapvFull(writev, fd, iov, count);
} }
#ifdef FOLLY_HAVE_PWRITEV
ssize_t pwritevFull(int fd, iovec* iov, int count, off_t offset) { ssize_t pwritevFull(int fd, iovec* iov, int count, off_t offset) {
return wrapvFull(pwritev, fd, iov, count, offset); return wrapvFull(pwritev, fd, iov, count, offset);
} }
#endif
} // namespaces } // namespaces
...@@ -17,6 +17,8 @@ ...@@ -17,6 +17,8 @@
#ifndef FOLLY_FILEUTIL_H_ #ifndef FOLLY_FILEUTIL_H_
#define FOLLY_FILEUTIL_H_ #define FOLLY_FILEUTIL_H_
#include "folly/Portability.h"
#include <sys/uio.h> #include <sys/uio.h>
#include <unistd.h> #include <unistd.h>
...@@ -63,7 +65,9 @@ ssize_t writevNoInt(int fd, const iovec* iov, int count); ...@@ -63,7 +65,9 @@ ssize_t writevNoInt(int fd, const iovec* iov, int count);
ssize_t readFull(int fd, void* buf, size_t n); 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 preadFull(int fd, void* buf, size_t n, off_t offset);
ssize_t readvFull(int fd, iovec* iov, int count); 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); ssize_t preadvFull(int fd, iovec* iov, int count, off_t offset);
#endif
/** /**
* Similar to readFull and preadFull above, wrappers around write() and * Similar to readFull and preadFull above, wrappers around write() and
...@@ -82,7 +86,9 @@ ssize_t preadvFull(int fd, iovec* iov, int count, off_t offset); ...@@ -82,7 +86,9 @@ ssize_t preadvFull(int fd, iovec* iov, int count, off_t offset);
ssize_t writeFull(int fd, const void* buf, size_t n); 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 pwriteFull(int fd, const void* buf, size_t n, off_t offset);
ssize_t writevFull(int fd, iovec* iov, int count); 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); ssize_t pwritevFull(int fd, iovec* iov, int count, off_t offset);
#endif
} // namespaces } // namespaces
......
...@@ -43,7 +43,7 @@ namespace folly { ...@@ -43,7 +43,7 @@ namespace folly {
#pragma GCC system_header #pragma GCC system_header
#define FOLLY_HAVE_MALLOC_H 1 #define FOLLY_HAVE_MALLOC_H 1
#else #else
#include "folly-config.h" #include "folly/Portability.h"
#endif #endif
// for malloc_usable_size // for malloc_usable_size
......
...@@ -19,6 +19,11 @@ ...@@ -19,6 +19,11 @@
#include "folly-config.h" #include "folly-config.h"
#ifdef FOLLY_HAVE_FEATURES_H
#include <features.h>
#endif
#ifdef FOLLY_HAVE_SCHED_H #ifdef FOLLY_HAVE_SCHED_H
#include <sched.h> #include <sched.h>
#ifndef FOLLY_HAVE_PTHREAD_YIELD #ifndef FOLLY_HAVE_PTHREAD_YIELD
...@@ -34,10 +39,36 @@ struct MaxAlign { char c; } __attribute__((aligned)); ...@@ -34,10 +39,36 @@ struct MaxAlign { char c; } __attribute__((aligned));
# error Cannot define MaxAlign on this platform # error Cannot define MaxAlign on this platform
#endif #endif
// noreturn
#if defined(__clang__) || defined(__GNUC__) #if defined(__clang__) || defined(__GNUC__)
# define FOLLY_NORETURN __attribute__((noreturn)) # define FOLLY_NORETURN __attribute__((noreturn))
#else #else
# define FOLLY_NORETURN # define FOLLY_NORETURN
#endif #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_ #endif // FOLLY_PORTABILITY_H_
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
#ifndef FOLLY_RANGE_H_ #ifndef FOLLY_RANGE_H_
#define FOLLY_RANGE_H_ #define FOLLY_RANGE_H_
#include "folly/folly-config.h" #include "folly/Portability.h"
#include "folly/FBString.h" #include "folly/FBString.h"
#include <glog/logging.h> #include <glog/logging.h>
#include <algorithm> #include <algorithm>
......
...@@ -38,7 +38,7 @@ AX_BOOST_SYSTEM ...@@ -38,7 +38,7 @@ AX_BOOST_SYSTEM
# Checks for header files. # Checks for header files.
AC_HEADER_STDC 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( AC_CHECK_HEADER(double-conversion.h, [], [AC_MSG_ERROR(
[Couldn't find double-conversion.h, please download from \ [Couldn't find double-conversion.h, please download from \
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include "folly/Exception.h" #include "folly/Exception.h"
#include "folly/FileUtil.h" #include "folly/FileUtil.h"
#include "folly/Memory.h" #include "folly/Memory.h"
#include "folly/Portability.h"
#include "folly/ScopeGuard.h" #include "folly/ScopeGuard.h"
#include "folly/String.h" #include "folly/String.h"
...@@ -51,11 +52,19 @@ void RecordIOWriter::write(std::unique_ptr<IOBuf> buf) { ...@@ -51,11 +52,19 @@ void RecordIOWriter::write(std::unique_ptr<IOBuf> buf) {
} }
DCHECK_EQ(buf->computeChainDataLength(), totalLength); DCHECK_EQ(buf->computeChainDataLength(), totalLength);
auto iov = buf->getIov();
// We're going to write. Reserve space for ourselves. // We're going to write. Reserve space for ourselves.
off_t pos = filePos_.fetch_add(totalLength); 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); 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"); checkUnixError(bytes, "pwrite() failed");
DCHECK_EQ(bytes, totalLength); DCHECK_EQ(bytes, totalLength);
} }
......
...@@ -222,6 +222,7 @@ TEST_F(FileUtilTest, readv) { ...@@ -222,6 +222,7 @@ TEST_F(FileUtilTest, readv) {
} }
} }
#ifdef FOLLY_HAVE_PREADV
TEST_F(FileUtilTest, preadv) { TEST_F(FileUtilTest, preadv) {
for (auto& p : readers_) { for (auto& p : readers_) {
IovecBuffers buf({12, 19, 31}); IovecBuffers buf({12, 19, 31});
...@@ -235,6 +236,7 @@ TEST_F(FileUtilTest, preadv) { ...@@ -235,6 +236,7 @@ TEST_F(FileUtilTest, preadv) {
} }
} }
} }
#endif
}} // namespaces }} // namespaces
......
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