} else if (!S_ISREG(st.st_mode)) { /* Regular files are OK regardless if O_PATH or not, for all other
* types check O_PATH flag */
- int flags;
-
- flags = fcntl(fd, F_GETFL);
- if (flags < 0)
- return -errno;
-
- if (!FLAGS_SET(flags, O_PATH)) /* If O_PATH this refers to the inode in the fs, in which case
- * we can sensibly do what is requested. Otherwise this refers
- * to a socket, fifo or device node, where the concept of a
- * containing directory doesn't make too much sense. */
+ r = fd_is_opath(fd);
+ if (r < 0)
+ return r;
+ if (!r) /* If O_PATH this refers to the inode in the fs, in which case we can sensibly do
+ * what is requested. Otherwise this refers to a socket, fifo or device node, where
+ * the concept of a containing directory doesn't make too much sense. */
return -ENOTTY;
}