// Failed attempt to test if O_NONBLOCK was set in open #include #include #include #include // O_RDONLY #include int main(int argc, char* argv[]) { const int BUF_SIZE = 81; char buffer[BUF_SIZE]; if (argc == 1) { fprintf(stderr, "Usage: %s pathname\n", argv[0]); exit(EXIT_FAILURE); } int fd = open(argv[1], O_RDONLY | O_NONBLOCK); if (fd < 0) perror("Failed to open"); int flags = fcntl(fd, F_GETFL); if (flags & O_NONBLOCK == O_NONBLOCK) // if ((flags & O_NONBLOCK) == O_NONBLOCK) puts("O_NONBLOCK was enabled in open."); else puts("O_NONBLOCK was NOT enabled in open."); }