forked from wenjun1055/c
-
Notifications
You must be signed in to change notification settings - Fork 0
/
3.4.c
60 lines (47 loc) · 1.04 KB
/
3.4.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
int main (int argc, char **argv)
{
int val;
if (2 != argc) {
printf("Usage: a.out <descriptor#>\n");
exit(-1);
}
if ((val = fcntl(atoi(argv[1]), F_GETFL, 0)) < 0) {
printf("fcntl error for fd %d \n", atoi(*argv+1));
exit(-1);
}
switch (val & O_ACCMODE) {
case O_RDONLY:
printf("read only");
break;
case O_WRONLY:
printf("write only");
break;
case O_RDWR:
printf("read write");
break;
default:
printf("unknown access mode");
exit(-1);
}
if (val & O_APPEND) {
printf(", append");
}
if (val & O_NONBLOCK) {
printf(", nonblock");
}
#if defined(O_SYNC)
if (val & O_SYNC) {
printf(", sync writes");
}
#endif
#if !defined(_POSIX_C_SOURCE) && defined(O_FSYNC)
if (val & O_FSYNC) {
printf(", sync writes");
}
#endif
putchar('\n');
return 0;
}