19 #define UMDF_USING_NTSTATUS 34 template <
class F,
class...
Args>
36 off_t origLoc = lseek(fd, 0, SEEK_CUR);
37 if (origLoc == (off_t)-1) {
40 if (lseek(fd, offset, SEEK_SET) == (off_t)-1) {
44 int res = (int)
f(fd, args...);
47 if (lseek(fd, origLoc, SEEK_SET) == (off_t)-1) {
59 namespace portability {
61 int access(
char const* fn,
int am) {
62 return _access(fn, am);
65 int chdir(
const char* path) {
70 if (folly::portability::sockets::is_fh_socket(fh)) {
80 int dup2(
int fhs,
int fhd) {
81 return _dup2(fhs, fhd);
85 HANDLE
h = (HANDLE)_get_osfhandle(fd);
86 if (h == INVALID_HANDLE_VALUE) {
89 if (!FlushFileBuffers(h)) {
95 int ftruncate(
int fd, off_t len) {
96 if (_lseek(fd, len, SEEK_SET) == -1) {
100 HANDLE
h = (HANDLE)_get_osfhandle(fd);
101 if (h == INVALID_HANDLE_VALUE) {
104 if (!SetEndOfFile(h)) {
110 char* getcwd(
char* buf,
int sz) {
111 return _getcwd(buf, sz);
114 int getdtablesize() {
115 return _getmaxstdio();
123 return (pid_t)
uint64_t(GetCurrentProcessId());
140 int lockf(
int fd,
int cmd, off_t len) {
141 return _locking(fd, cmd, len);
144 off_t lseek(
int fh, off_t off,
int orig) {
145 return _lseek(fh, off, orig);
148 int rmdir(
const char* path) {
152 int pipe(
int pth[2]) {
155 return socketpair(PF_UNIX, SOCK_STREAM, 0, pth);
158 ssize_t pread(
int fd,
void* buf,
size_t count, off_t offset) {
159 return wrapPositional(_read, fd, offset, buf, (
unsigned int)count);
162 ssize_t pwrite(
int fd,
const void* buf,
size_t count, off_t offset) {
163 return wrapPositional(_write, fd, offset, buf, (
unsigned int)count);
166 ssize_t
read(
int fh,
void* buf,
size_t count) {
167 if (folly::portability::sockets::is_fh_socket(fh)) {
168 SOCKET
s = (SOCKET)_get_osfhandle(fh);
169 if (s != INVALID_SOCKET) {
171 if (r == -1 && WSAGetLastError() == WSAEWOULDBLOCK) {
177 auto r = _read(fh, buf, static_cast<unsigned int>(count));
178 if (r == -1 && GetLastError() == ERROR_NO_DATA) {
187 ssize_t readlink(
const char* path,
char* buf,
size_t buflen) {
192 HANDLE
h = CreateFileA(
198 FILE_FLAG_BACKUP_SEMANTICS,
200 if (h == INVALID_HANDLE_VALUE) {
205 GetFinalPathNameByHandleA(h, buf, DWORD(buflen - 1), VOLUME_NAME_DOS);
206 if (ret >= buflen || ret >= MAX_PATH || !ret) {
216 void* sbrk(intptr_t ) {
220 unsigned int sleep(
unsigned int seconds) {
221 Sleep((DWORD)(seconds * 1000));
225 long sysconf(
int tp) {
230 return (
long)inf.dwPageSize;
232 case _SC_NPROCESSORS_ONLN: {
235 return (
long)inf.dwNumberOfProcessors;
242 int truncate(
const char* path, off_t len) {
243 int fd = _open(path, O_WRONLY);
247 if (ftruncate(fd, len)) {
251 return _close(fd) ? -1 : 0;
254 int usleep(
unsigned int ms) {
255 Sleep((DWORD)(ms / 1000));
259 ssize_t
write(
int fh,
void const* buf,
size_t count) {
260 if (folly::portability::sockets::is_fh_socket(fh)) {
261 SOCKET
s = (SOCKET)_get_osfhandle(fh);
262 if (s != INVALID_SOCKET) {
264 if (r == -1 && WSAGetLastError() == WSAEWOULDBLOCK) {
270 auto r = _write(fh, buf, static_cast<unsigned int>(count));
271 if ((r > 0 &&
size_t(r) != count) || (r == -1 && errno == ENOSPC)) {
276 HANDLE
h = (HANDLE)_get_osfhandle(fh);
277 if (GetFileType(h) == FILE_TYPE_PIPE) {
279 if (GetNamedPipeHandleState(
280 h, &state,
nullptr,
nullptr,
nullptr,
nullptr, 0)) {
281 if ((state & PIPE_NOWAIT) == PIPE_NOWAIT) {
void write(const T &in, folly::io::Appender &appender)
Future< Unit > sleep(Duration dur, Timekeeper *tk)
internal::ArgsMatcher< InnerMatcher > Args(const InnerMatcher &matcher)
static int close(int fd) noexcept
—— Concurrent Priority Queue Implementation ——
size_t read(T &out, folly::io::Cursor &cursor)
static int wrapPositional(F f, int fd, off_t offset, Args...args)
ssize_t send(NetworkSocket s, const void *buf, size_t len, int flags)
ssize_t recv(NetworkSocket s, void *buf, size_t len, int flags)
int close(NetworkSocket s)
void pipe(CPUExecutor cpu, IOExecutor io)
int socketpair(int domain, int type, int protocol, NetworkSocket sv[2])