diff --git a/third-party/folly/src/folly/portability/Fcntl.cpp b/third-party/folly/src/folly/portability/Fcntl.cpp index 15b726136ce96..01cf902997b77 100644 --- a/third-party/folly/src/folly/portability/Fcntl.cpp +++ b/third-party/folly/src/folly/portability/Fcntl.cpp @@ -24,10 +24,6 @@ namespace folly { namespace portability { namespace fcntl { -int creat(char const* fn, int pm) { - return _creat(fn, pm); -} - int fcntl(int fd, int cmd, ...) { va_list args; int res = -1; @@ -85,6 +81,15 @@ int fcntl(int fd, int cmd, ...) { return res; } +int posix_fallocate(int fd, off_t offset, off_t len) { + // We'll pretend we always have enough space. We + // can't exactly pre-allocate on windows anyways. + return 0; +} +} // namespace fcntl +} // namespace portability + +namespace fileops { int open(char const* fn, int of, int pm) { int fh; int realMode = _S_IREAD; @@ -108,13 +113,6 @@ int open(char const* fn, int of, int pm) { errno_t res = _sopen_s(&fh, fn, of, _SH_DENYNO, realMode); return res ? -1 : fh; } - -int posix_fallocate(int fd, off_t offset, off_t len) { - // We'll pretend we always have enough space. We - // can't exactly pre-allocate on windows anyways. - return 0; -} -} // namespace fcntl -} // namespace portability +} // namespace fileops } // namespace folly #endif diff --git a/third-party/folly/src/folly/portability/Fcntl.h b/third-party/folly/src/folly/portability/Fcntl.h index eb149e130a4ad..79e7adffb5025 100644 --- a/third-party/folly/src/folly/portability/Fcntl.h +++ b/third-party/folly/src/folly/portability/Fcntl.h @@ -46,10 +46,8 @@ namespace folly { namespace portability { namespace fcntl { -int creat(char const* fn, int pm); int fcntl(int fd, int cmd, ...); int posix_fallocate(int fd, off_t offset, off_t len); -int open(char const* fn, int of, int pm = 0); } // namespace fcntl } // namespace portability } // namespace folly @@ -69,7 +67,7 @@ FOLLY_POP_WARNING namespace folly { namespace fileops { #ifdef _WIN32 -using portability::fcntl::open; +int open(char const* fn, int of, int pm = 0); #else using ::open; #endif diff --git a/third-party/folly/src/folly/portability/Stdlib.h b/third-party/folly/src/folly/portability/Stdlib.h index db56a4e14c585..b6933de494a9c 100644 --- a/third-party/folly/src/folly/portability/Stdlib.h +++ b/third-party/folly/src/folly/portability/Stdlib.h @@ -62,7 +62,6 @@ int clearenv(); #endif #ifdef _WIN32 -char* mktemp(char* tn); char* mkdtemp(char* tn); int mkstemp(char* tn); char* realpath(const char* path, char* resolved_path); diff --git a/third-party/folly/src/folly/portability/SysStat.cpp b/third-party/folly/src/folly/portability/SysStat.cpp index 5db05f6b5d1c8..fa38dd554b9fa 100644 --- a/third-party/folly/src/folly/portability/SysStat.cpp +++ b/third-party/folly/src/folly/portability/SysStat.cpp @@ -22,10 +22,6 @@ namespace folly { namespace portability { namespace sysstat { -int chmod(char const* fn, int am) { - return _chmod(fn, am); -} - int fchmod(int fd, mode_t mode) { HANDLE h = (HANDLE)_get_osfhandle(fd); if (h == INVALID_HANDLE_VALUE) { @@ -60,10 +56,6 @@ int lstat(const char* path, struct stat* st) { int mkdir(const char* fn, int /* mode */) { return _mkdir(fn); } - -int umask(int md) { - return _umask(md); -} } // namespace sysstat } // namespace portability } // namespace folly diff --git a/third-party/folly/src/folly/portability/SysStat.h b/third-party/folly/src/folly/portability/SysStat.h index 0a6c0bd2feecc..6fb3d5d19221b 100644 --- a/third-party/folly/src/folly/portability/SysStat.h +++ b/third-party/folly/src/folly/portability/SysStat.h @@ -47,11 +47,9 @@ namespace folly { namespace portability { namespace sysstat { -int chmod(char const* fn, int am); int fchmod(int fd, mode_t mode); int lstat(const char* path, struct stat* st); int mkdir(const char* fn, int mode); -int umask(int md); } // namespace sysstat } // namespace portability } // namespace folly diff --git a/third-party/folly/src/folly/portability/Unistd.cpp b/third-party/folly/src/folly/portability/Unistd.cpp index 74f8f27b1d61f..9096cc6e55562 100644 --- a/third-party/folly/src/folly/portability/Unistd.cpp +++ b/third-party/folly/src/folly/portability/Unistd.cpp @@ -198,29 +198,6 @@ ProcessHandleWrapper getParentProcessHandle() { } } // namespace -int access(char const* fn, int am) { - return _access(fn, am); -} - -int chdir(const char* path) { - return _chdir(path); -} - -int close(int fh) { - if (folly::portability::sockets::is_fh_socket(fh)) { - return netops::detail::SocketFileDescriptorMap::close(fh); - } - return _close(fh); -} - -int dup(int fh) { - return _dup(fh); -} - -int dup2(int fhs, int fhd) { - return _dup2(fhs, fhd); -} - int fsync(int fd) { HANDLE h = (HANDLE)_get_osfhandle(fd); if (h == INVALID_HANDLE_VALUE) { @@ -254,10 +231,6 @@ int ftruncate(int fd, off_t len) { return 0; } -char* getcwd(char* buf, int sz) { - return _getcwd(buf, sz); -} - int getdtablesize() { return _getmaxstdio(); } @@ -278,32 +251,14 @@ uid_t getuid() { return 1; } -int isatty(int fh) { - return _isatty(fh); -} - 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); -} - off64_t lseek64(int fh, off64_t off, int orig) { return _lseeki64(fh, static_cast(off), orig); } -int rmdir(const char* path) { - return _rmdir(path); -} - -int pipe(int pth[2]) { - // We need to be able to listen to pipes with - // libevent, so they need to be actual sockets. - return socketpair(PF_UNIX, SOCK_STREAM, 0, pth); -} - ssize_t pread(int fd, void* buf, size_t count, off_t offset) { const bool is64Bit = false; return wrapPositional(_read, fd, offset, buf, (unsigned int)count); @@ -319,27 +274,6 @@ ssize_t pwrite(int fd, const void* buf, size_t count, off_t offset) { return wrapPositional(_write, fd, offset, buf, (unsigned int)count); } -ssize_t read(int fh, void* buf, size_t count) { - if (folly::portability::sockets::is_fh_socket(fh)) { - SOCKET s = (SOCKET)_get_osfhandle(fh); - if (s != INVALID_SOCKET) { - auto r = folly::portability::sockets::recv(fh, buf, count, 0); - if (r == -1 && WSAGetLastError() == WSAEWOULDBLOCK) { - errno = EAGAIN; - } - return r; - } - } - auto r = _read(fh, buf, static_cast(count)); - if (r == -1 && GetLastError() == ERROR_NO_DATA) { - // This only happens if the file was non-blocking and - // no data was present. We have to translate the error - // to a form that the rest of the world is expecting. - errno = EAGAIN; - } - return r; -} - ssize_t readlink(const char* path, char* buf, size_t buflen) { if (!buflen) { return -1; @@ -411,6 +345,43 @@ int usleep(unsigned int ms) { Sleep((DWORD)(ms / 1000)); return 0; } +} // namespace unistd +} // namespace portability + +namespace fileops { +int close(int fh) { + if (folly::portability::sockets::is_fh_socket(fh)) { + return netops::detail::SocketFileDescriptorMap::close(fh); + } + return _close(fh); +} + +ssize_t read(int fh, void* buf, size_t count) { + if (folly::portability::sockets::is_fh_socket(fh)) { + SOCKET s = (SOCKET)_get_osfhandle(fh); + if (s != INVALID_SOCKET) { + auto r = folly::portability::sockets::recv(fh, buf, count, 0); + if (r == -1 && WSAGetLastError() == WSAEWOULDBLOCK) { + errno = EAGAIN; + } + return r; + } + } + auto r = _read(fh, buf, static_cast(count)); + if (r == -1 && GetLastError() == ERROR_NO_DATA) { + // This only happens if the file was non-blocking and + // no data was present. We have to translate the error + // to a form that the rest of the world is expecting. + errno = EAGAIN; + } + return r; +} + +int pipe(int pth[2]) { + // We need to be able to listen to pipes with + // libevent, so they need to be actual sockets. + return socketpair(PF_UNIX, SOCK_STREAM, 0, pth); +} ssize_t write(int fh, void const* buf, size_t count) { if (folly::portability::sockets::is_fh_socket(fh)) { @@ -443,8 +414,7 @@ ssize_t write(int fh, void const* buf, size_t count) { } return r; } -} // namespace unistd -} // namespace portability +} // namespace fileops } // namespace folly #endif diff --git a/third-party/folly/src/folly/portability/Unistd.h b/third-party/folly/src/folly/portability/Unistd.h index 91e664e8c70b3..f52712c3cae24 100644 --- a/third-party/folly/src/folly/portability/Unistd.h +++ b/third-party/folly/src/folly/portability/Unistd.h @@ -71,25 +71,14 @@ namespace folly { namespace portability { namespace unistd { using off64_t = int64_t; -int access(char const* fn, int am); -int chdir(const char* path); -int close(int fh); -int dup(int fh); -int dup2(int fhs, int fhd); int fsync(int fd); int ftruncate(int fd, off_t len); -char* getcwd(char* buf, int sz); int getdtablesize(); int getgid(); pid_t getppid(); int getuid(); -int isatty(int fh); int lockf(int fd, int cmd, off_t len); -off_t lseek(int fh, off_t off, int orig); off64_t lseek64(int fh, off64_t off, int orig); -ssize_t read(int fh, void* buf, size_t mcc); -int rmdir(const char* path); -int pipe(int pth[2]); ssize_t pread(int fd, void* buf, size_t count, off_t offset); ssize_t pread64(int fd, void* buf, size_t count, off64_t offset); ssize_t pwrite(int fd, const void* buf, size_t count, off_t offset); @@ -99,7 +88,6 @@ unsigned int sleep(unsigned int seconds); long sysconf(int tp); int truncate(const char* path, off_t len); int usleep(unsigned int ms); -ssize_t write(int fh, void const* buf, size_t count); } // namespace unistd } // namespace portability } // namespace folly @@ -113,10 +101,10 @@ FOLLY_POP_WARNING namespace folly { namespace fileops { #ifdef _WIN32 -using folly::portability::unistd::close; -using folly::portability::unistd::pipe; -using folly::portability::unistd::read; -using folly::portability::unistd::write; +int close(int fh); +ssize_t read(int fh, void* buf, size_t mcc); +int pipe(int pth[2]); +ssize_t write(int fh, void const* buf, size_t count); #else using ::close; using ::pipe; diff --git a/third-party/folly/src/folly/portability/Windows.h b/third-party/folly/src/folly/portability/Windows.h index 1e4e80167faaf..d6f4cc9f98594 100644 --- a/third-party/folly/src/folly/portability/Windows.h +++ b/third-party/folly/src/folly/portability/Windows.h @@ -32,24 +32,8 @@ // disabled to ensure all of the normal names get declared properly. #include -#ifndef __STDC__ -/* nolint */ -#define __STDC__ 1 -#pragma push_macro("_CRT_DECLARE_NONSTDC_NAMES") -#ifdef _CRT_DECLARE_NONSTDC_NAMES -#undef _CRT_DECLARE_NONSTDC_NAMES -#endif -#pragma push_macro("_CRT_INTERNAL_NONSTDC_NAMES") -#undef _CRT_INTERNAL_NONSTDC_NAMES -#include // @manual nolint -#include // @manual nolint -#undef __STDC__ -#pragma pop_macro("_CRT_INTERNAL_NONSTDC_NAMES") -#pragma pop_macro("_CRT_DECLARE_NONSTDC_NAMES") -#else #include // @manual nolint #include // @manual nolint -#endif #if defined(min) || defined(max) #error Windows.h needs to be included by this header, or else NOMINMAX needs \