/* * Sample program for fcntl system call - No.55 * * fcntl - manipulate file descriptor * * Synopsis * #include * #include * * int fcntl(int fd, int cmd); * int fcntl(int fd, int cmd, long arg); * int fcntl(int fd, int cmd, struct flock *lock); * * Description * fcntl performs one of various miscellaneous operations on * fd. The operation in question is determined by cmd: * ................... * F_GETFL Read the descriptor's flags (all flags (as set by * open(2)) are returned). * ................... * see 'man fcntl' for more information. */ #include #include #define BYTESIZE 8 void printbits(int flag) { int i; for (i = 0; i < BYTESIZE * sizeof(flag); ++i) printf("%d", (flag << i & 1 << BYTESIZE * sizeof(flag) -1) ? 1 : 0); putchar('\n'); } main() { int fd, flag; fd = open("fcntl.c", O_RDONLY | O_NONBLOCK); flag = fcntl(fd, F_GETFL); printf("O_NONBLOCK is set\n"); printf("flag = "); printbits(flag); exit(0); }