about summary refs log tree commit homepage
path: root/ext/clogger_ext/clogger.c
diff options
context:
space:
mode:
Diffstat (limited to 'ext/clogger_ext/clogger.c')
-rw-r--r--ext/clogger_ext/clogger.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/ext/clogger_ext/clogger.c b/ext/clogger_ext/clogger.c
index 838f37c..834debe 100644
--- a/ext/clogger_ext/clogger.c
+++ b/ext/clogger_ext/clogger.c
@@ -260,7 +260,17 @@ static int raw_fd(VALUE my_fd)
         if (flags < 0)
                 rb_sys_fail("fcntl");
 
-        return (flags & O_NONBLOCK) ? -1 : fd;
+        if (flags & O_NONBLOCK) {
+                struct stat sb;
+
+                if (fstat(fd, &sb) < 0)
+                        return -1;
+
+                /* O_NONBLOCK is no-op for regular files: */
+                if (! S_ISREG(sb.st_mode))
+                        return -1;
+        }
+        return fd;
 #else /* platforms w/o fcntl/F_GETFL/O_NONBLOCK */
         return -1;
 #endif /* platforms w/o fcntl/F_GETFL/O_NONBLOCK */