#include <folly/Portability.h>
#ifdef _MSC_VER
-# include <intrin.h>
+#include <intrin.h>
#endif
namespace folly {
#else
-FOLLY_NAMESPACE_STD_BEGIN
+namespace std {
#if _LIBCPP_VERSION < 4000
void __throw_length_error(char const* msg) {
throw std::bad_alloc();
}
#endif
-
-FOLLY_NAMESPACE_STD_END
+}
#endif
#else
-FOLLY_NAMESPACE_STD_BEGIN
+namespace std {
#if _LIBCPP_VERSION < 4000
-[[noreturn]] void __throw_length_error(char const* msg); // @nolint
+[[noreturn]] void __throw_length_error(char const* msg);
[[noreturn]] void __throw_logic_error(char const* msg);
[[noreturn]] void __throw_out_of_range(char const* msg);
#endif
#if _CPPLIB_VER // msvc c++ std lib
[[noreturn]] void __throw_bad_alloc();
#endif
-
-FOLLY_NAMESPACE_STD_END
+}
#endif
FOLLY_ALWAYS_INLINE int __builtin_clz(unsigned int x) {
unsigned long index;
- return (int)(_BitScanReverse(&index, (unsigned long)x) ? 31 - index : 32);
+ return int(_BitScanReverse(&index, (unsigned long)x) ? 31 - index : 32);
}
FOLLY_ALWAYS_INLINE int __builtin_clzl(unsigned long x) {
FOLLY_ALWAYS_INLINE int __builtin_clzll(unsigned long long x) {
unsigned long index;
- return (int)(_BitScanReverse64(&index, x) ? 63 - index : 64);
+ return int(_BitScanReverse64(&index, x) ? 63 - index : 64);
}
FOLLY_ALWAYS_INLINE int __builtin_ctzll(unsigned long long x) {
unsigned long index;
- return (int)(_BitScanForward64(&index, x) ? index : 64);
+ return int(_BitScanForward64(&index, x) ? index : 64);
}
FOLLY_ALWAYS_INLINE int __builtin_ffs(int x) {
unsigned long index;
- return (int)(_BitScanForward(&index, (unsigned long)x) ? index + 1 : 0);
+ return int(_BitScanForward(&index, (unsigned long)x) ? index + 1 : 0);
}
-FOLLY_ALWAYS_INLINE int __builtin_ffsl(long x) { return __builtin_ffs((int)x); }
+FOLLY_ALWAYS_INLINE int __builtin_ffsl(long x) {
+ return __builtin_ffs(int(x));
+}
FOLLY_ALWAYS_INLINE int __builtin_ffsll(long long x) {
unsigned long index;
- return (int)(_BitScanForward64(&index, (unsigned long long)x) ? index + 1 : 0);
+ return int(_BitScanForward64(&index, (unsigned long long)x) ? index + 1 : 0);
}
FOLLY_ALWAYS_INLINE int __builtin_popcountll(unsigned long long x) {
- return (int)__popcnt64(x);
+ return int(__popcnt64(x));
}
FOLLY_ALWAYS_INLINE void* __builtin_return_address(unsigned int frame) {
constexpr size_t constexpr_strlen_internal(const Char* s, size_t len) {
return *s == Char(0) ? len : constexpr_strlen_internal(s + 1, len + 1);
}
-static_assert(constexpr_strlen_internal("123456789", 0) == 9,
- "Someone appears to have broken constexpr_strlen...");
+static_assert(
+ constexpr_strlen_internal("123456789", 0) == 9,
+ "Someone appears to have broken constexpr_strlen...");
} // namespace detail
template <typename Char>
#ifdef _MSC_VER
// This needs to be before the libevent include.
-# include <folly/portability/Windows.h>
+#include <folly/portability/Windows.h>
#endif
#include <event.h>
#ifdef _MSC_VER
-# include <event2/event_compat.h>
-# include <folly/portability/Fcntl.h>
+#include <event2/event_compat.h>
+#include <folly/portability/Fcntl.h>
#endif
namespace folly {
namespace folly {
namespace portability {
namespace fcntl {
-int creat(char const* fn, int pm) { return _creat(fn, pm); }
+int creat(char const* fn, int pm) {
+ return _creat(fn, pm);
+}
int fcntl(int fd, int cmd, ...) {
va_list args;
namespace folly {
namespace detail {
-#if _POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600 || \
- (defined(__ANDROID__) && (__ANDROID_API__ > 15)) || \
- (defined(__APPLE__) && (__MAC_OS_X_VERSION_MIN_REQUIRED >= __MAC_10_6 || \
- __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_3_0))
+#if _POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600 || \
+ (defined(__ANDROID__) && (__ANDROID_API__ > 15)) || \
+ (defined(__APPLE__) && \
+ (__MAC_OS_X_VERSION_MIN_REQUIRED >= __MAC_10_6 || \
+ __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_3_0))
// Use posix_memalign, but mimic the behaviour of memalign
void* aligned_malloc(size_t size, size_t align) {
// OPENSSL_VERSION_NUMBER to maintain compatibility. The following variables are
// intended to be specific to OpenSSL.
#if !defined(OPENSSL_IS_BORINGSSL)
-# define FOLLY_OPENSSL_IS_100 \
+#define FOLLY_OPENSSL_IS_100 \
(OPENSSL_VERSION_NUMBER >= 0x10000003L && \
OPENSSL_VERSION_NUMBER < 0x1000105fL)
-# define FOLLY_OPENSSL_IS_101 \
+#define FOLLY_OPENSSL_IS_101 \
(OPENSSL_VERSION_NUMBER >= 0x1000105fL && \
OPENSSL_VERSION_NUMBER < 0x1000200fL)
-# define FOLLY_OPENSSL_IS_102 \
+#define FOLLY_OPENSSL_IS_102 \
(OPENSSL_VERSION_NUMBER >= 0x1000200fL && \
OPENSSL_VERSION_NUMBER < 0x10100000L)
-# define FOLLY_OPENSSL_IS_110 (OPENSSL_VERSION_NUMBER >= 0x10100000L)
+#define FOLLY_OPENSSL_IS_110 (OPENSSL_VERSION_NUMBER >= 0x10100000L)
#endif
-#if !OPENSSL_IS_BORINGSSL && !FOLLY_OPENSSL_IS_100 && !FOLLY_OPENSSL_IS_101 \
- && !FOLLY_OPENSSL_IS_102 && !FOLLY_OPENSSL_IS_110
-# warning Compiling with unsupported OpenSSL version
+#if !OPENSSL_IS_BORINGSSL && !FOLLY_OPENSSL_IS_100 && !FOLLY_OPENSSL_IS_101 && \
+ !FOLLY_OPENSSL_IS_102 && !FOLLY_OPENSSL_IS_110
+#warning Compiling with unsupported OpenSSL version
#endif
// BoringSSL and OpenSSL 0.9.8f later with TLS extension support SNI.
-#if OPENSSL_IS_BORINGSSL || \
+#if OPENSSL_IS_BORINGSSL || \
(OPENSSL_VERSION_NUMBER >= 0x00908070L && !defined(OPENSSL_NO_TLSEXT))
-# define FOLLY_OPENSSL_HAS_SNI 1
+#define FOLLY_OPENSSL_HAS_SNI 1
#else
-# define FOLLY_OPENSSL_HAS_SNI 0
+#define FOLLY_OPENSSL_HAS_SNI 0
#endif
// BoringSSL and OpenSSL 1.0.2 later with TLS extension support ALPN.
-#if OPENSSL_IS_BORINGSSL || \
+#if OPENSSL_IS_BORINGSSL || \
(OPENSSL_VERSION_NUMBER >= 0x1000200fL && !defined(OPENSSL_NO_TLSEXT))
-# define FOLLY_OPENSSL_HAS_ALPN 1
+#define FOLLY_OPENSSL_HAS_ALPN 1
#else
-# define FOLLY_OPENSSL_HAS_ALPN 0
+#define FOLLY_OPENSSL_HAS_ALPN 0
#endif
// This attempts to "unify" the OpenSSL libcrypto/libssl APIs between
// minor version upgrade will need to remove this
#define OPENSSL_lh_new OPENSSL_LH_new
#endif
-
}
}
}
WSADATA dat;
WSAStartup(MAKEWORD(2, 2), &dat);
}
- ~FSPInit() { WSACleanup(); }
+ ~FSPInit() {
+ WSACleanup();
+ }
} fspInit;
bool is_fh_socket(int fh) {
msg.dwFlags = 0;
msg.dwBufferCount = (DWORD)message->msg_iovlen;
msg.lpBuffers = new WSABUF[message->msg_iovlen];
- SCOPE_EXIT { delete[] msg.lpBuffers; };
+ SCOPE_EXIT {
+ delete[] msg.lpBuffers;
+ };
for (size_t i = 0; i < message->msg_iovlen; i++) {
msg.lpBuffers[i].buf = (CHAR*)message->msg_iov[i].iov_base;
msg.lpBuffers[i].len = (ULONG)message->msg_iov[i].iov_len;
#include <folly/portability/Stdio.h>
#ifdef _WIN32
+
#include <cstdlib>
+
#include <folly/ScopeGuard.h>
#include <folly/portability/Unistd.h>
int dprintf(int fd, const char* fmt, ...) {
va_list args;
va_start(args, fmt);
- SCOPE_EXIT { va_end(args); };
+ SCOPE_EXIT {
+ va_end(args);
+ };
int ret = vsnprintf(nullptr, 0, fmt, args);
if (ret <= 0) {
}
size_t len = size_t(ret);
char* buf = new char[len + 1];
- SCOPE_EXIT { delete[] buf; };
+ SCOPE_EXIT {
+ delete[] buf;
+ };
if (size_t(vsnprintf(buf, len + 1, fmt, args)) == len &&
write(fd, buf, len) == ssize_t(len)) {
return ret;
return -1;
}
-int pclose(FILE* f) { return _pclose(f); }
+int pclose(FILE* f) {
+ return _pclose(f);
+}
-FILE* popen(const char* name, const char* mode) { return _popen(name, mode); }
+FILE* popen(const char* name, const char* mode) {
+ return _popen(name, mode);
+}
void setbuffer(FILE* f, char* buf, size_t size) {
setvbuf(f, buf, _IOFBF, size);
return -1;
}
}
+
#endif
#include <folly/portability/Stdlib.h>
#ifdef _WIN32
+
#include <cstring>
+
#include <errno.h>
#include <folly/portability/Fcntl.h>
#include <folly/portability/Windows.h>
extern "C" {
-char* mktemp(char* tn) { return _mktemp(tn); }
+char* mktemp(char* tn) {
+ return _mktemp(tn);
+}
// While yes, this is for a directory, due to this being windows,
// a file and directory can't have the same name, resulting in this
return 0;
}
}
+
#endif
#if !__linux__ && !FOLLY_MOBILE
+
#include <string>
#include <vector>
return 0;
}
+
#endif
#pragma once
-#include <string.h>
#include <stdlib.h>
+#include <string.h>
#include <folly/portability/Config.h>
#include <folly/portability/SysMman.h>
#ifdef _WIN32
+
#include <cassert>
+
#include <folly/Portability.h>
#include <folly/portability/Windows.h>
return 0;
}
}
+
#endif
#pragma once
#ifndef _WIN32
+
#include <sys/mman.h>
// MAP_ANONYMOUS is named MAP_ANON on OSX/BSD.
#if defined(__APPLE__) || defined(__FreeBSD__)
-# if !defined(MAP_ANONYMOUS) && defined(MAP_ANON)
-# define MAP_ANONYMOUS MAP_ANON
-# endif
+#if !defined(MAP_ANONYMOUS) && defined(MAP_ANON)
+#define MAP_ANONYMOUS MAP_ANON
+#endif
#endif
+
#else
+
#include <cstdint>
+
#include <sys/types.h>
#define MAP_ANONYMOUS 1
int munlock(const void* addr, size_t length);
int munmap(void* addr, size_t length);
}
+
#endif
#include <folly/portability/Windows.h>
extern "C" {
-int chmod(char const* fn, int am) { return _chmod(fn, am); }
+int chmod(char const* fn, int am) {
+ return _chmod(fn, am);
+}
int fchmod(int fd, mode_t mode) {
HANDLE h = (HANDLE)_get_osfhandle(fd);
}
// Just return the result of a normal stat for now
-int lstat(const char* path, struct stat* st) { return stat(path, st); }
+int lstat(const char* path, struct stat* st) {
+ return stat(path, st);
+}
int mkdir(const char* fn, int /* mode */) {
return _mkdir(fn);
}
-int umask(int md) { return _umask(md); }
+int umask(int md) {
+ return _umask(md);
+}
}
#endif
#define S_IRWXU (S_IRUSR | S_IWUSR | S_IXUSR)
#define S_IRWXG (S_IRGRP | S_IWGRP | S_IXGRP)
-#define S_ISDIR(mode) (((mode) & _S_IFDIR) == _S_IFDIR ? 1 : 0)
+#define S_ISDIR(mode) (((mode) & (_S_IFDIR)) == (_S_IFDIR) ? 1 : 0)
// This isn't defined anywhere, so give a sane value.
#define MAXSYMLINKS 255
#include <folly/portability/SysTime.h>
#ifdef _WIN32
+
#include <cstdint>
+
#include <Windows.h>
extern "C" {
}
}
}
+
#endif
if (lockf(fd, F_LOCK, 0) == -1) {
return -1;
}
- SCOPE_EXIT { lockf(fd, F_ULOCK, 0); };
+ SCOPE_EXIT {
+ lockf(fd, F_ULOCK, 0);
+ };
ssize_t bytesProcessed = 0;
int curIov = 0;
return 0;
}
-char* strptime(const char* __restrict s,
- const char* __restrict f,
- struct tm* __restrict tm) {
+char* strptime(
+ const char* __restrict s,
+ const char* __restrict f,
+ struct tm* __restrict tm) {
// Isn't the C++ standard lib nice? std::get_time is defined such that its
// format parameters are the exact same as strptime. Of course, we have to
// create a string stream first, and imbue it with the current C locale, and
// solve that by pretending we have it here in the header and
// then enable our implementation on the source side so that
// gets linked in instead.
-#if __MACH__ && ( \
- MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_12 || \
- __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_10_0)
+#if __MACH__ && \
+ (MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_12 || \
+ __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_10_0)
-# ifdef FOLLY_HAVE_CLOCK_GETTIME
-# undef FOLLY_HAVE_CLOCK_GETTIME
-# endif
+#ifdef FOLLY_HAVE_CLOCK_GETTIME
+#undef FOLLY_HAVE_CLOCK_GETTIME
+#endif
-# define FOLLY_HAVE_CLOCK_GETTIME 1
-# define FOLLY_FORCE_CLOCK_GETTIME_DEFINITION 1
+#define FOLLY_HAVE_CLOCK_GETTIME 1
+#define FOLLY_FORCE_CLOCK_GETTIME_DEFINITION 1
#endif
tm* gmtime_r(const time_t* t, tm* res);
tm* localtime_r(const time_t* t, tm* o);
int nanosleep(const struct timespec* request, struct timespec* remain);
-char* strptime(const char* __restrict buf,
- const char* __restrict fmt,
- struct tm* __restrict tm);
+char* strptime(
+ const char* __restrict buf,
+ const char* __restrict fmt,
+ struct tm* __restrict tm);
}
#endif
#include <folly/portability/Unistd.h>
#ifdef _WIN32
+
#include <cstdio>
+
#include <fcntl.h>
+
#include <folly/portability/Sockets.h>
#include <folly/portability/Windows.h>
namespace folly {
namespace portability {
namespace unistd {
-int access(char const* fn, int am) { return _access(fn, am); }
+int access(char const* fn, int am) {
+ return _access(fn, am);
+}
-int chdir(const char* path) { return _chdir(path); }
+int chdir(const char* path) {
+ return _chdir(path);
+}
int close(int fh) {
if (folly::portability::sockets::is_fh_socket(fh)) {
return _close(fh);
}
-int dup(int fh) { return _dup(fh); }
+int dup(int fh) {
+ return _dup(fh);
+}
-int dup2(int fhs, int fhd) { return _dup2(fhs, fhd); }
+int dup2(int fhs, int fhd) {
+ return _dup2(fhs, fhd);
+}
int fsync(int fd) {
HANDLE h = (HANDLE)_get_osfhandle(fd);
return 0;
}
-char* getcwd(char* buf, int sz) { return _getcwd(buf, sz); }
+char* getcwd(char* buf, int sz) {
+ return _getcwd(buf, sz);
+}
-int getdtablesize() { return _getmaxstdio(); }
+int getdtablesize() {
+ return _getmaxstdio();
+}
-int getgid() { return 1; }
+int getgid() {
+ return 1;
+}
-pid_t getpid() { return (pid_t)uint64_t(GetCurrentProcessId()); }
+pid_t getpid() {
+ return (pid_t)uint64_t(GetCurrentProcessId());
+}
// No major need to implement this, and getting a non-potentially
// stale ID on windows is a bit involved.
-pid_t getppid() { return (pid_t)1; }
+pid_t getppid() {
+ return (pid_t)1;
+}
-int getuid() { return 1; }
+int getuid() {
+ return 1;
+}
-int isatty(int fh) { return _isatty(fh); }
+int isatty(int fh) {
+ return _isatty(fh);
+}
-int lockf(int fd, int cmd, off_t len) { return _locking(fd, cmd, len); }
+int lockf(int fd, int cmd, off_t len) {
+ return _locking(fd, cmd, len);
+}
off_t lseek(int fh, off_t off, int orig) {
return _lseek(fh, off, orig);
}
-int rmdir(const char* path) { return _rmdir(path); }
+int rmdir(const char* path) {
+ return _rmdir(path);
+}
int pipe(int pth[2]) {
// We need to be able to listen to pipes with
}
}
}
+
#endif
#pragma once
#ifndef _WIN32
+
#include <unistd.h>
+
#else
+
#include <cstdint>
+
#include <sys/locking.h>
+
#include <folly/portability/SysTypes.h>
// This is different from the normal headers because there are a few cases,
}
/* using override */ using namespace folly::portability::unistd;
+
#endif
#ifndef __STDC__
/* nolint */
#define __STDC__ 1
-#include <io.h> // nolint
#include <direct.h> // nolint
+#include <io.h> // nolint
#undef __STDC__
#else
-#include <io.h> // nolint
#include <direct.h> // nolint
+#include <io.h> // nolint
#endif
#if defined(min) || defined(max)
#include <folly/portability/Time.h>
-#include <folly/test/TestUtils.h>
#include <folly/portability/GTest.h>
+#include <folly/test/TestUtils.h>
#include <chrono>