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 @@ ...@@ -19,7 +19,7 @@
#include <folly/Portability.h> #include <folly/Portability.h>
#ifdef _MSC_VER #ifdef _MSC_VER
# include <intrin.h> #include <intrin.h>
#endif #endif
namespace folly { namespace folly {
......
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
#else #else
FOLLY_NAMESPACE_STD_BEGIN namespace std {
#if _LIBCPP_VERSION < 4000 #if _LIBCPP_VERSION < 4000
void __throw_length_error(char const* msg) { void __throw_length_error(char const* msg) {
...@@ -45,7 +45,6 @@ void __throw_bad_alloc() { ...@@ -45,7 +45,6 @@ void __throw_bad_alloc() {
throw std::bad_alloc(); throw std::bad_alloc();
} }
#endif #endif
}
FOLLY_NAMESPACE_STD_END
#endif #endif
...@@ -27,10 +27,10 @@ ...@@ -27,10 +27,10 @@
#else #else
FOLLY_NAMESPACE_STD_BEGIN namespace std {
#if _LIBCPP_VERSION < 4000 #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_logic_error(char const* msg);
[[noreturn]] void __throw_out_of_range(char const* msg); [[noreturn]] void __throw_out_of_range(char const* msg);
#endif #endif
...@@ -38,7 +38,6 @@ FOLLY_NAMESPACE_STD_BEGIN ...@@ -38,7 +38,6 @@ FOLLY_NAMESPACE_STD_BEGIN
#if _CPPLIB_VER // msvc c++ std lib #if _CPPLIB_VER // msvc c++ std lib
[[noreturn]] void __throw_bad_alloc(); [[noreturn]] void __throw_bad_alloc();
#endif #endif
}
FOLLY_NAMESPACE_STD_END
#endif #endif
...@@ -43,7 +43,7 @@ FOLLY_ALWAYS_INLINE void __builtin___clear_cache(char* begin, char* end) { ...@@ -43,7 +43,7 @@ FOLLY_ALWAYS_INLINE void __builtin___clear_cache(char* begin, char* end) {
FOLLY_ALWAYS_INLINE int __builtin_clz(unsigned int x) { FOLLY_ALWAYS_INLINE int __builtin_clz(unsigned int x) {
unsigned long index; 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_clzl(unsigned long x) {
...@@ -52,28 +52,30 @@ 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) { FOLLY_ALWAYS_INLINE int __builtin_clzll(unsigned long long x) {
unsigned long index; 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) { FOLLY_ALWAYS_INLINE int __builtin_ctzll(unsigned long long x) {
unsigned long index; 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) { FOLLY_ALWAYS_INLINE int __builtin_ffs(int x) {
unsigned long index; 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) { FOLLY_ALWAYS_INLINE int __builtin_ffsll(long long x) {
unsigned long index; 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) { 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) { FOLLY_ALWAYS_INLINE void* __builtin_return_address(unsigned int frame) {
......
...@@ -87,8 +87,9 @@ template <typename Char> ...@@ -87,8 +87,9 @@ template <typename Char>
constexpr size_t constexpr_strlen_internal(const Char* s, size_t len) { constexpr size_t constexpr_strlen_internal(const Char* s, size_t len) {
return *s == Char(0) ? len : constexpr_strlen_internal(s + 1, len + 1); return *s == Char(0) ? len : constexpr_strlen_internal(s + 1, len + 1);
} }
static_assert(constexpr_strlen_internal("123456789", 0) == 9, static_assert(
"Someone appears to have broken constexpr_strlen..."); constexpr_strlen_internal("123456789", 0) == 9,
"Someone appears to have broken constexpr_strlen...");
} // namespace detail } // namespace detail
template <typename Char> template <typename Char>
......
...@@ -18,14 +18,14 @@ ...@@ -18,14 +18,14 @@
#ifdef _MSC_VER #ifdef _MSC_VER
// This needs to be before the libevent include. // This needs to be before the libevent include.
# include <folly/portability/Windows.h> #include <folly/portability/Windows.h>
#endif #endif
#include <event.h> #include <event.h>
#ifdef _MSC_VER #ifdef _MSC_VER
# include <event2/event_compat.h> #include <event2/event_compat.h>
# include <folly/portability/Fcntl.h> #include <folly/portability/Fcntl.h>
#endif #endif
namespace folly { namespace folly {
......
...@@ -24,7 +24,9 @@ ...@@ -24,7 +24,9 @@
namespace folly { namespace folly {
namespace portability { namespace portability {
namespace fcntl { 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, ...) { int fcntl(int fd, int cmd, ...) {
va_list args; va_list args;
......
...@@ -23,10 +23,11 @@ ...@@ -23,10 +23,11 @@
namespace folly { namespace folly {
namespace detail { namespace detail {
#if _POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600 || \ #if _POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600 || \
(defined(__ANDROID__) && (__ANDROID_API__ > 15)) || \ (defined(__ANDROID__) && (__ANDROID_API__ > 15)) || \
(defined(__APPLE__) && (__MAC_OS_X_VERSION_MIN_REQUIRED >= __MAC_10_6 || \ (defined(__APPLE__) && \
__IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_3_0)) (__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 // Use posix_memalign, but mimic the behaviour of memalign
void* aligned_malloc(size_t size, size_t align) { void* aligned_malloc(size_t size, size_t align) {
......
...@@ -174,7 +174,6 @@ void HMAC_CTX_free(HMAC_CTX* ctx) { ...@@ -174,7 +174,6 @@ void HMAC_CTX_free(HMAC_CTX* ctx) {
} }
#endif #endif
} }
} }
} }
...@@ -47,37 +47,37 @@ ...@@ -47,37 +47,37 @@
// OPENSSL_VERSION_NUMBER to maintain compatibility. The following variables are // OPENSSL_VERSION_NUMBER to maintain compatibility. The following variables are
// intended to be specific to OpenSSL. // intended to be specific to OpenSSL.
#if !defined(OPENSSL_IS_BORINGSSL) #if !defined(OPENSSL_IS_BORINGSSL)
# define FOLLY_OPENSSL_IS_100 \ #define FOLLY_OPENSSL_IS_100 \
(OPENSSL_VERSION_NUMBER >= 0x10000003L && \ (OPENSSL_VERSION_NUMBER >= 0x10000003L && \
OPENSSL_VERSION_NUMBER < 0x1000105fL) OPENSSL_VERSION_NUMBER < 0x1000105fL)
# define FOLLY_OPENSSL_IS_101 \ #define FOLLY_OPENSSL_IS_101 \
(OPENSSL_VERSION_NUMBER >= 0x1000105fL && \ (OPENSSL_VERSION_NUMBER >= 0x1000105fL && \
OPENSSL_VERSION_NUMBER < 0x1000200fL) OPENSSL_VERSION_NUMBER < 0x1000200fL)
# define FOLLY_OPENSSL_IS_102 \ #define FOLLY_OPENSSL_IS_102 \
(OPENSSL_VERSION_NUMBER >= 0x1000200fL && \ (OPENSSL_VERSION_NUMBER >= 0x1000200fL && \
OPENSSL_VERSION_NUMBER < 0x10100000L) OPENSSL_VERSION_NUMBER < 0x10100000L)
# define FOLLY_OPENSSL_IS_110 (OPENSSL_VERSION_NUMBER >= 0x10100000L) #define FOLLY_OPENSSL_IS_110 (OPENSSL_VERSION_NUMBER >= 0x10100000L)
#endif #endif
#if !OPENSSL_IS_BORINGSSL && !FOLLY_OPENSSL_IS_100 && !FOLLY_OPENSSL_IS_101 \ #if !OPENSSL_IS_BORINGSSL && !FOLLY_OPENSSL_IS_100 && !FOLLY_OPENSSL_IS_101 && \
&& !FOLLY_OPENSSL_IS_102 && !FOLLY_OPENSSL_IS_110 !FOLLY_OPENSSL_IS_102 && !FOLLY_OPENSSL_IS_110
# warning Compiling with unsupported OpenSSL version #warning Compiling with unsupported OpenSSL version
#endif #endif
// BoringSSL and OpenSSL 0.9.8f later with TLS extension support SNI. // 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)) (OPENSSL_VERSION_NUMBER >= 0x00908070L && !defined(OPENSSL_NO_TLSEXT))
# define FOLLY_OPENSSL_HAS_SNI 1 #define FOLLY_OPENSSL_HAS_SNI 1
#else #else
# define FOLLY_OPENSSL_HAS_SNI 0 #define FOLLY_OPENSSL_HAS_SNI 0
#endif #endif
// BoringSSL and OpenSSL 1.0.2 later with TLS extension support ALPN. // 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)) (OPENSSL_VERSION_NUMBER >= 0x1000200fL && !defined(OPENSSL_NO_TLSEXT))
# define FOLLY_OPENSSL_HAS_ALPN 1 #define FOLLY_OPENSSL_HAS_ALPN 1
#else #else
# define FOLLY_OPENSSL_HAS_ALPN 0 #define FOLLY_OPENSSL_HAS_ALPN 0
#endif #endif
// This attempts to "unify" the OpenSSL libcrypto/libssl APIs between // 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); ...@@ -138,7 +138,6 @@ STACK_OF(X509) * X509_STORE_CTX_get0_untrusted(X509_STORE_CTX* ctx);
// minor version upgrade will need to remove this // minor version upgrade will need to remove this
#define OPENSSL_lh_new OPENSSL_LH_new #define OPENSSL_lh_new OPENSSL_LH_new
#endif #endif
} }
} }
} }
......
...@@ -37,7 +37,9 @@ static struct FSPInit { ...@@ -37,7 +37,9 @@ static struct FSPInit {
WSADATA dat; WSADATA dat;
WSAStartup(MAKEWORD(2, 2), &dat); WSAStartup(MAKEWORD(2, 2), &dat);
} }
~FSPInit() { WSACleanup(); } ~FSPInit() {
WSACleanup();
}
} fspInit; } fspInit;
bool is_fh_socket(int fh) { bool is_fh_socket(int fh) {
...@@ -271,7 +273,9 @@ ssize_t recvmsg(int s, struct msghdr* message, int /* flags */) { ...@@ -271,7 +273,9 @@ ssize_t recvmsg(int s, struct msghdr* message, int /* flags */) {
msg.dwFlags = 0; msg.dwFlags = 0;
msg.dwBufferCount = (DWORD)message->msg_iovlen; msg.dwBufferCount = (DWORD)message->msg_iovlen;
msg.lpBuffers = new WSABUF[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++) { for (size_t i = 0; i < message->msg_iovlen; i++) {
msg.lpBuffers[i].buf = (CHAR*)message->msg_iov[i].iov_base; msg.lpBuffers[i].buf = (CHAR*)message->msg_iov[i].iov_base;
msg.lpBuffers[i].len = (ULONG)message->msg_iov[i].iov_len; msg.lpBuffers[i].len = (ULONG)message->msg_iov[i].iov_len;
......
...@@ -17,7 +17,9 @@ ...@@ -17,7 +17,9 @@
#include <folly/portability/Stdio.h> #include <folly/portability/Stdio.h>
#ifdef _WIN32 #ifdef _WIN32
#include <cstdlib> #include <cstdlib>
#include <folly/ScopeGuard.h> #include <folly/ScopeGuard.h>
#include <folly/portability/Unistd.h> #include <folly/portability/Unistd.h>
...@@ -25,7 +27,9 @@ extern "C" { ...@@ -25,7 +27,9 @@ extern "C" {
int dprintf(int fd, const char* fmt, ...) { int dprintf(int fd, const char* fmt, ...) {
va_list args; va_list args;
va_start(args, fmt); va_start(args, fmt);
SCOPE_EXIT { va_end(args); }; SCOPE_EXIT {
va_end(args);
};
int ret = vsnprintf(nullptr, 0, fmt, args); int ret = vsnprintf(nullptr, 0, fmt, args);
if (ret <= 0) { if (ret <= 0) {
...@@ -33,7 +37,9 @@ int dprintf(int fd, const char* fmt, ...) { ...@@ -33,7 +37,9 @@ int dprintf(int fd, const char* fmt, ...) {
} }
size_t len = size_t(ret); size_t len = size_t(ret);
char* buf = new char[len + 1]; char* buf = new char[len + 1];
SCOPE_EXIT { delete[] buf; }; SCOPE_EXIT {
delete[] buf;
};
if (size_t(vsnprintf(buf, len + 1, fmt, args)) == len && if (size_t(vsnprintf(buf, len + 1, fmt, args)) == len &&
write(fd, buf, len) == ssize_t(len)) { write(fd, buf, len) == ssize_t(len)) {
return ret; return ret;
...@@ -42,9 +48,13 @@ int dprintf(int fd, const char* fmt, ...) { ...@@ -42,9 +48,13 @@ int dprintf(int fd, const char* fmt, ...) {
return -1; 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) { void setbuffer(FILE* f, char* buf, size_t size) {
setvbuf(f, buf, _IOFBF, size); setvbuf(f, buf, _IOFBF, size);
...@@ -63,4 +73,5 @@ int vasprintf(char** dest, const char* format, va_list ap) { ...@@ -63,4 +73,5 @@ int vasprintf(char** dest, const char* format, va_list ap) {
return -1; return -1;
} }
} }
#endif #endif
...@@ -17,7 +17,9 @@ ...@@ -17,7 +17,9 @@
#include <folly/portability/Stdlib.h> #include <folly/portability/Stdlib.h>
#ifdef _WIN32 #ifdef _WIN32
#include <cstring> #include <cstring>
#include <errno.h> #include <errno.h>
#include <folly/portability/Fcntl.h> #include <folly/portability/Fcntl.h>
...@@ -25,7 +27,9 @@ ...@@ -25,7 +27,9 @@
#include <folly/portability/Windows.h> #include <folly/portability/Windows.h>
extern "C" { 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, // 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 // a file and directory can't have the same name, resulting in this
...@@ -135,9 +139,11 @@ int unsetenv(const char* name) { ...@@ -135,9 +139,11 @@ int unsetenv(const char* name) {
return 0; return 0;
} }
} }
#endif #endif
#if !__linux__ && !FOLLY_MOBILE #if !__linux__ && !FOLLY_MOBILE
#include <string> #include <string>
#include <vector> #include <vector>
...@@ -162,4 +168,5 @@ extern "C" int clearenv() { ...@@ -162,4 +168,5 @@ extern "C" int clearenv() {
return 0; return 0;
} }
#endif #endif
...@@ -16,8 +16,8 @@ ...@@ -16,8 +16,8 @@
#pragma once #pragma once
#include <string.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h>
#include <folly/portability/Config.h> #include <folly/portability/Config.h>
......
...@@ -17,7 +17,9 @@ ...@@ -17,7 +17,9 @@
#include <folly/portability/SysMman.h> #include <folly/portability/SysMman.h>
#ifdef _WIN32 #ifdef _WIN32
#include <cassert> #include <cassert>
#include <folly/Portability.h> #include <folly/Portability.h>
#include <folly/portability/Windows.h> #include <folly/portability/Windows.h>
...@@ -213,4 +215,5 @@ int munmap(void* addr, size_t length) { ...@@ -213,4 +215,5 @@ int munmap(void* addr, size_t length) {
return 0; return 0;
} }
} }
#endif #endif
...@@ -17,16 +17,20 @@ ...@@ -17,16 +17,20 @@
#pragma once #pragma once
#ifndef _WIN32 #ifndef _WIN32
#include <sys/mman.h> #include <sys/mman.h>
// MAP_ANONYMOUS is named MAP_ANON on OSX/BSD. // MAP_ANONYMOUS is named MAP_ANON on OSX/BSD.
#if defined(__APPLE__) || defined(__FreeBSD__) #if defined(__APPLE__) || defined(__FreeBSD__)
# if !defined(MAP_ANONYMOUS) && defined(MAP_ANON) #if !defined(MAP_ANONYMOUS) && defined(MAP_ANON)
# define MAP_ANONYMOUS MAP_ANON #define MAP_ANONYMOUS MAP_ANON
# endif #endif
#endif #endif
#else #else
#include <cstdint> #include <cstdint>
#include <sys/types.h> #include <sys/types.h>
#define MAP_ANONYMOUS 1 #define MAP_ANONYMOUS 1
...@@ -56,4 +60,5 @@ int mprotect(void* addr, size_t size, int prot); ...@@ -56,4 +60,5 @@ int mprotect(void* addr, size_t size, int prot);
int munlock(const void* addr, size_t length); int munlock(const void* addr, size_t length);
int munmap(void* addr, size_t length); int munmap(void* addr, size_t length);
} }
#endif #endif
...@@ -20,7 +20,9 @@ ...@@ -20,7 +20,9 @@
#include <folly/portability/Windows.h> #include <folly/portability/Windows.h>
extern "C" { 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) { int fchmod(int fd, mode_t mode) {
HANDLE h = (HANDLE)_get_osfhandle(fd); HANDLE h = (HANDLE)_get_osfhandle(fd);
...@@ -49,12 +51,16 @@ int fchmod(int fd, mode_t mode) { ...@@ -49,12 +51,16 @@ int fchmod(int fd, mode_t mode) {
} }
// Just return the result of a normal stat for now // 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 */) { int mkdir(const char* fn, int /* mode */) {
return _mkdir(fn); return _mkdir(fn);
} }
int umask(int md) { return _umask(md); } int umask(int md) {
return _umask(md);
}
} }
#endif #endif
...@@ -35,7 +35,7 @@ ...@@ -35,7 +35,7 @@
#define S_IRWXU (S_IRUSR | S_IWUSR | S_IXUSR) #define S_IRWXU (S_IRUSR | S_IWUSR | S_IXUSR)
#define S_IRWXG (S_IRGRP | S_IWGRP | S_IXGRP) #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. // This isn't defined anywhere, so give a sane value.
#define MAXSYMLINKS 255 #define MAXSYMLINKS 255
......
...@@ -17,7 +17,9 @@ ...@@ -17,7 +17,9 @@
#include <folly/portability/SysTime.h> #include <folly/portability/SysTime.h>
#ifdef _WIN32 #ifdef _WIN32
#include <cstdint> #include <cstdint>
#include <Windows.h> #include <Windows.h>
extern "C" { extern "C" {
...@@ -58,4 +60,5 @@ void timersub(timeval* a, timeval* b, timeval* res) { ...@@ -58,4 +60,5 @@ void timersub(timeval* a, timeval* b, timeval* res) {
} }
} }
} }
#endif #endif
...@@ -73,7 +73,9 @@ static ssize_t doVecOperation(int fd, const iovec* iov, int count) { ...@@ -73,7 +73,9 @@ static ssize_t doVecOperation(int fd, const iovec* iov, int count) {
if (lockf(fd, F_LOCK, 0) == -1) { if (lockf(fd, F_LOCK, 0) == -1) {
return -1; return -1;
} }
SCOPE_EXIT { lockf(fd, F_ULOCK, 0); }; SCOPE_EXIT {
lockf(fd, F_ULOCK, 0);
};
ssize_t bytesProcessed = 0; ssize_t bytesProcessed = 0;
int curIov = 0; int curIov = 0;
......
...@@ -325,9 +325,10 @@ int nanosleep(const struct timespec* request, struct timespec* remain) { ...@@ -325,9 +325,10 @@ int nanosleep(const struct timespec* request, struct timespec* remain) {
return 0; return 0;
} }
char* strptime(const char* __restrict s, char* strptime(
const char* __restrict f, const char* __restrict s,
struct tm* __restrict tm) { const char* __restrict f,
struct tm* __restrict tm) {
// Isn't the C++ standard lib nice? std::get_time is defined such that its // 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 // 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 // create a string stream first, and imbue it with the current C locale, and
......
...@@ -27,16 +27,16 @@ ...@@ -27,16 +27,16 @@
// solve that by pretending we have it here in the header and // solve that by pretending we have it here in the header and
// then enable our implementation on the source side so that // then enable our implementation on the source side so that
// gets linked in instead. // gets linked in instead.
#if __MACH__ && ( \ #if __MACH__ && \
MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_12 || \ (MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_12 || \
__IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_10_0) __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_10_0)
# ifdef FOLLY_HAVE_CLOCK_GETTIME #ifdef FOLLY_HAVE_CLOCK_GETTIME
# undef FOLLY_HAVE_CLOCK_GETTIME #undef FOLLY_HAVE_CLOCK_GETTIME
# endif #endif
# define FOLLY_HAVE_CLOCK_GETTIME 1 #define FOLLY_HAVE_CLOCK_GETTIME 1
# define FOLLY_FORCE_CLOCK_GETTIME_DEFINITION 1 #define FOLLY_FORCE_CLOCK_GETTIME_DEFINITION 1
#endif #endif
...@@ -62,8 +62,9 @@ char* ctime_r(const time_t* t, char* buf); ...@@ -62,8 +62,9 @@ char* ctime_r(const time_t* t, char* buf);
tm* gmtime_r(const time_t* t, tm* res); tm* gmtime_r(const time_t* t, tm* res);
tm* localtime_r(const time_t* t, tm* o); tm* localtime_r(const time_t* t, tm* o);
int nanosleep(const struct timespec* request, struct timespec* remain); int nanosleep(const struct timespec* request, struct timespec* remain);
char* strptime(const char* __restrict buf, char* strptime(
const char* __restrict fmt, const char* __restrict buf,
struct tm* __restrict tm); const char* __restrict fmt,
struct tm* __restrict tm);
} }
#endif #endif
...@@ -21,8 +21,11 @@ ...@@ -21,8 +21,11 @@
#include <folly/portability/Unistd.h> #include <folly/portability/Unistd.h>
#ifdef _WIN32 #ifdef _WIN32
#include <cstdio> #include <cstdio>
#include <fcntl.h> #include <fcntl.h>
#include <folly/portability/Sockets.h> #include <folly/portability/Sockets.h>
#include <folly/portability/Windows.h> #include <folly/portability/Windows.h>
...@@ -60,9 +63,13 @@ static int wrapPositional(F f, int fd, off_t offset, Args... args) { ...@@ -60,9 +63,13 @@ static int wrapPositional(F f, int fd, off_t offset, Args... args) {
namespace folly { namespace folly {
namespace portability { namespace portability {
namespace unistd { 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) { int close(int fh) {
if (folly::portability::sockets::is_fh_socket(fh)) { if (folly::portability::sockets::is_fh_socket(fh)) {
...@@ -111,9 +118,13 @@ int close(int fh) { ...@@ -111,9 +118,13 @@ int close(int fh) {
return _close(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) { int fsync(int fd) {
HANDLE h = (HANDLE)_get_osfhandle(fd); HANDLE h = (HANDLE)_get_osfhandle(fd);
...@@ -141,29 +152,47 @@ int ftruncate(int fd, off_t len) { ...@@ -141,29 +152,47 @@ int ftruncate(int fd, off_t len) {
return 0; 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 // No major need to implement this, and getting a non-potentially
// stale ID on windows is a bit involved. // 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) { off_t lseek(int fh, off_t off, int orig) {
return _lseek(fh, off, 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]) { int pipe(int pth[2]) {
// We need to be able to listen to pipes with // 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) { ...@@ -306,4 +335,5 @@ ssize_t write(int fh, void const* buf, size_t count) {
} }
} }
} }
#endif #endif
...@@ -17,10 +17,15 @@ ...@@ -17,10 +17,15 @@
#pragma once #pragma once
#ifndef _WIN32 #ifndef _WIN32
#include <unistd.h> #include <unistd.h>
#else #else
#include <cstdint> #include <cstdint>
#include <sys/locking.h> #include <sys/locking.h>
#include <folly/portability/SysTypes.h> #include <folly/portability/SysTypes.h>
// This is different from the normal headers because there are a few cases, // 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); ...@@ -86,4 +91,5 @@ ssize_t write(int fh, void const* buf, size_t count);
} }
/* using override */ using namespace folly::portability::unistd; /* using override */ using namespace folly::portability::unistd;
#endif #endif
...@@ -29,12 +29,12 @@ ...@@ -29,12 +29,12 @@
#ifndef __STDC__ #ifndef __STDC__
/* nolint */ /* nolint */
#define __STDC__ 1 #define __STDC__ 1
#include <io.h> // nolint
#include <direct.h> // nolint #include <direct.h> // nolint
#include <io.h> // nolint
#undef __STDC__ #undef __STDC__
#else #else
#include <io.h> // nolint
#include <direct.h> // nolint #include <direct.h> // nolint
#include <io.h> // nolint
#endif #endif
#if defined(min) || defined(max) #if defined(min) || defined(max)
......
...@@ -16,8 +16,8 @@ ...@@ -16,8 +16,8 @@
#include <folly/portability/Time.h> #include <folly/portability/Time.h>
#include <folly/test/TestUtils.h>
#include <folly/portability/GTest.h> #include <folly/portability/GTest.h>
#include <folly/test/TestUtils.h>
#include <chrono> #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