Commit 1b67e9aa authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook Github Bot

Apply clang-format to folly/portability/

Summary:
[Folly] Apply `clang-format` to `folly/portability/`.

With some manual rearrangement in the places where `clang-format` does awkward things, with the result that `clang-format` over `folly/portability/` becomes a no-op.

Reviewed By: igorsugak

Differential Revision: D5170107

fbshipit-source-id: ceadd96740b4877cbae947846f0e738e6aaf5ed1
parent 5fc76bd2
......@@ -19,7 +19,7 @@
#include <folly/Portability.h>
#ifdef _MSC_VER
# include <intrin.h>
#include <intrin.h>
#endif
namespace folly {
......
......@@ -24,7 +24,7 @@
#else
FOLLY_NAMESPACE_STD_BEGIN
namespace std {
#if _LIBCPP_VERSION < 4000
void __throw_length_error(char const* msg) {
......@@ -45,7 +45,6 @@ void __throw_bad_alloc() {
throw std::bad_alloc();
}
#endif
FOLLY_NAMESPACE_STD_END
}
#endif
......@@ -27,10 +27,10 @@
#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
......@@ -38,7 +38,6 @@ FOLLY_NAMESPACE_STD_BEGIN
#if _CPPLIB_VER // msvc c++ std lib
[[noreturn]] void __throw_bad_alloc();
#endif
FOLLY_NAMESPACE_STD_END
}
#endif
......@@ -43,7 +43,7 @@ FOLLY_ALWAYS_INLINE void __builtin___clear_cache(char* begin, char* end) {
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) {
......@@ -52,28 +52,30 @@ 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) {
......
......@@ -87,8 +87,9 @@ template <typename Char>
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>
......
......@@ -18,14 +18,14 @@
#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 {
......
......@@ -24,7 +24,9 @@
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;
......
......@@ -23,10 +23,11 @@
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) {
......
......@@ -174,7 +174,6 @@ void HMAC_CTX_free(HMAC_CTX* ctx) {
}
#endif
}
}
}
......@@ -47,37 +47,37 @@
// 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
......@@ -138,7 +138,6 @@ STACK_OF(X509) * X509_STORE_CTX_get0_untrusted(X509_STORE_CTX* ctx);
// minor version upgrade will need to remove this
#define OPENSSL_lh_new OPENSSL_LH_new
#endif
}
}
}
......
......@@ -37,7 +37,9 @@ static struct FSPInit {
WSADATA dat;
WSAStartup(MAKEWORD(2, 2), &dat);
}
~FSPInit() { WSACleanup(); }
~FSPInit() {
WSACleanup();
}
} fspInit;
bool is_fh_socket(int fh) {
......@@ -271,7 +273,9 @@ ssize_t recvmsg(int s, struct msghdr* message, int /* flags */) {
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;
......
......@@ -17,7 +17,9 @@
#include <folly/portability/Stdio.h>
#ifdef _WIN32
#include <cstdlib>
#include <folly/ScopeGuard.h>
#include <folly/portability/Unistd.h>
......@@ -25,7 +27,9 @@ extern "C" {
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) {
......@@ -33,7 +37,9 @@ int dprintf(int fd, const char* fmt, ...) {
}
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;
......@@ -42,9 +48,13 @@ int dprintf(int fd, const char* fmt, ...) {
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);
......@@ -63,4 +73,5 @@ int vasprintf(char** dest, const char* format, va_list ap) {
return -1;
}
}
#endif
......@@ -17,7 +17,9 @@
#include <folly/portability/Stdlib.h>
#ifdef _WIN32
#include <cstring>
#include <errno.h>
#include <folly/portability/Fcntl.h>
......@@ -25,7 +27,9 @@
#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
......@@ -135,9 +139,11 @@ int unsetenv(const char* name) {
return 0;
}
}
#endif
#if !__linux__ && !FOLLY_MOBILE
#include <string>
#include <vector>
......@@ -162,4 +168,5 @@ extern "C" int clearenv() {
return 0;
}
#endif
......@@ -16,8 +16,8 @@
#pragma once
#include <string.h>
#include <stdlib.h>
#include <string.h>
#include <folly/portability/Config.h>
......
......@@ -17,7 +17,9 @@
#include <folly/portability/SysMman.h>
#ifdef _WIN32
#include <cassert>
#include <folly/Portability.h>
#include <folly/portability/Windows.h>
......@@ -213,4 +215,5 @@ int munmap(void* addr, size_t length) {
return 0;
}
}
#endif
......@@ -17,16 +17,20 @@
#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
......@@ -56,4 +60,5 @@ int mprotect(void* addr, size_t size, int prot);
int munlock(const void* addr, size_t length);
int munmap(void* addr, size_t length);
}
#endif
......@@ -20,7 +20,9 @@
#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);
......@@ -49,12 +51,16 @@ int fchmod(int fd, mode_t mode) {
}
// 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
......@@ -35,7 +35,7 @@
#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
......
......@@ -17,7 +17,9 @@
#include <folly/portability/SysTime.h>
#ifdef _WIN32
#include <cstdint>
#include <Windows.h>
extern "C" {
......@@ -58,4 +60,5 @@ void timersub(timeval* a, timeval* b, timeval* res) {
}
}
}
#endif
......@@ -73,7 +73,9 @@ static ssize_t doVecOperation(int fd, const iovec* iov, int count) {
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;
......
......@@ -325,9 +325,10 @@ int nanosleep(const struct timespec* request, struct timespec* remain) {
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
......
......@@ -27,16 +27,16 @@
// 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
......@@ -62,8 +62,9 @@ char* ctime_r(const time_t* t, char* buf);
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
......@@ -21,8 +21,11 @@
#include <folly/portability/Unistd.h>
#ifdef _WIN32
#include <cstdio>
#include <fcntl.h>
#include <folly/portability/Sockets.h>
#include <folly/portability/Windows.h>
......@@ -60,9 +63,13 @@ static int wrapPositional(F f, int fd, off_t offset, Args... args) {
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)) {
......@@ -111,9 +118,13 @@ int close(int 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);
......@@ -141,29 +152,47 @@ int ftruncate(int fd, off_t len) {
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
......@@ -306,4 +335,5 @@ ssize_t write(int fh, void const* buf, size_t count) {
}
}
}
#endif
......@@ -17,10 +17,15 @@
#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,
......@@ -86,4 +91,5 @@ ssize_t write(int fh, void const* buf, size_t count);
}
/* using override */ using namespace folly::portability::unistd;
#endif
......@@ -29,12 +29,12 @@
#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)
......
......@@ -16,8 +16,8 @@
#include <folly/portability/Time.h>
#include <folly/test/TestUtils.h>
#include <folly/portability/GTest.h>
#include <folly/test/TestUtils.h>
#include <chrono>
......
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