25 namespace portability {
27 int creat(
char const* fn,
int pm) {
28 return _creat(fn, pm);
31 int fcntl(
int fd,
int cmd, ...) {
37 HANDLE
h = (HANDLE)_get_osfhandle(fd);
38 if (h != INVALID_HANDLE_VALUE) {
40 if (GetHandleInformation(h, &flags)) {
41 res = int(flags & HANDLE_FLAG_INHERIT);
47 int flags = va_arg(args,
int);
48 HANDLE h = (HANDLE)_get_osfhandle(fd);
49 if (h != INVALID_HANDLE_VALUE) {
50 if (SetHandleInformation(
51 h, HANDLE_FLAG_INHERIT, (DWORD)(flags & FD_CLOEXEC))) {
63 int flags = va_arg(args,
int);
65 if (folly::portability::sockets::is_fh_socket(fd)) {
66 SOCKET
s = (SOCKET)_get_osfhandle(fd);
67 if (s != INVALID_SOCKET) {
68 u_long nonBlockingEnabled = (flags & O_NONBLOCK) ? 1 : 0;
69 res = ioctlsocket(s, FIONBIO, &nonBlockingEnabled);
72 HANDLE p = (HANDLE)_get_osfhandle(fd);
73 if (GetFileType(p) == FILE_TYPE_PIPE) {
74 DWORD newMode = PIPE_READMODE_BYTE;
75 newMode |= (flags & O_NONBLOCK) ? PIPE_NOWAIT : PIPE_WAIT;
76 if (SetNamedPipeHandleState(p, &newMode,
nullptr,
nullptr)) {
88 int open(
char const* fn,
int of,
int pm) {
90 int realMode = _S_IREAD;
91 if ((of & _O_RDWR) == _O_RDWR) {
92 realMode = _S_IREAD | _S_IWRITE;
93 }
else if ((of & _O_WRONLY) == _O_WRONLY) {
95 }
else if ((of & _O_RDONLY) != _O_RDONLY) {
100 if (!strcmp(fn,
"/dev/null")) {
105 errno_t res = _sopen_s(&fh, fn, of, _SH_DENYNO, realMode);
106 return res ? -1 : fh;
109 int posix_fallocate(
int fd, off_t offset, off_t len) {
—— Concurrent Priority Queue Implementation ——