Move folly/AtomicStruct.h to folly/synchronization/
[folly.git] / folly / portability / Fcntl.cpp
old mode 100755 (executable)
new mode 100644 (file)
index 757a63f..5d8e7ec
@@ -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;
@@ -36,7 +38,7 @@ int fcntl(int fd, int cmd, ...) {
       if (h != INVALID_HANDLE_VALUE) {
         DWORD flags;
         if (GetHandleInformation(h, &flags)) {
-          res = flags & HANDLE_FLAG_INHERIT;
+          res = int(flags & HANDLE_FLAG_INHERIT);
         }
       }
       break;
@@ -59,21 +61,20 @@ int fcntl(int fd, int cmd, ...) {
     }
     case F_SETFL: {
       int flags = va_arg(args, int);
-      if (flags & O_NONBLOCK) {
-        // If it's not a socket, it's probably a pipe.
-        if (folly::portability::sockets::is_fh_socket(fd)) {
-          SOCKET s = (SOCKET)_get_osfhandle(fd);
-          if (s != INVALID_SOCKET) {
-            u_long nonBlockingEnabled = 1;
-            res = ioctlsocket(s, FIONBIO, &nonBlockingEnabled);
-          }
-        } else {
-          HANDLE p = (HANDLE)_get_osfhandle(fd);
-          if (GetFileType(p) == FILE_TYPE_PIPE) {
-            DWORD newMode = PIPE_READMODE_BYTE | PIPE_NOWAIT;
-            if (SetNamedPipeHandleState(p, &newMode, nullptr, nullptr)) {
-              res = 0;
-            }
+      // If it's not a socket, it's probably a pipe.
+      if (folly::portability::sockets::is_fh_socket(fd)) {
+        SOCKET s = (SOCKET)_get_osfhandle(fd);
+        if (s != INVALID_SOCKET) {
+          u_long nonBlockingEnabled = (flags & O_NONBLOCK) ? 1 : 0;
+          res = ioctlsocket(s, FIONBIO, &nonBlockingEnabled);
+        }
+      } else {
+        HANDLE p = (HANDLE)_get_osfhandle(fd);
+        if (GetFileType(p) == FILE_TYPE_PIPE) {
+          DWORD newMode = PIPE_READMODE_BYTE;
+          newMode |= (flags & O_NONBLOCK) ? PIPE_NOWAIT : PIPE_WAIT;
+          if (SetNamedPipeHandleState(p, &newMode, nullptr, nullptr)) {
+            res = 0;
           }
         }
       }