|
[code:1]
// getfl
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
int main(int argc, char **argv)
{
const char *my_name = argv[0];
int val, accmode;
if (argc != 2) {
fprintf(stderr, "usage: a.out <decriptor#>\n");
exit(0);
}
if ((val = fcntl(atoi(argv[1]), F_GETFL, 0)) < 0) {
perror(my_name);
exit(0);
}
accmode = val & O_ACCMODE; // 这里以下如何理解
switch (accmode) {
case O_RDONLY:
printf("read only");
break;
case O_WRONLY:
printf("write only");
break;
case O_RDWR:
printf("read write");
break;
}
if (val & O_APPEND)
printf(", append");
if (val & O_NONBLOCK)
printf(", nonblocking");
printf("\n");
}
[/code:1]
以及 ACCMODE O_APPEND O_NONBLOCK的取值在哪里可以找到 |
|