1#include <sys/types.h>
2#include <sys/stat.h>
3#include <fcntl.h>
4
5#ifndef O_DIRECT
6#define O_DIRECT 00040000
7#endif
8
9#ifndef O_DIRECTORY
10#define O_DIRECTORY 00200000
11#endif
12
13#ifndef O_NOATIME
14#define O_NOATIME 01000000
15#endif
16
17#ifndef O_TMPFILE
18#define O_TMPFILE 020000000
19#endif
20
21#undef O_LARGEFILE
22#define O_LARGEFILE 00100000
23
24size_t open__scnprintf_flags(unsigned long flags, char *bf, size_t size)
25{
26 int printed = 0;
27
28 if (flags == 0)
29 return scnprintf(bf, size, "RDONLY");
30#define P_FLAG(n) \
31 if (flags & O_##n) { \
32 printed += scnprintf(bf + printed, size - printed, "%s%s", printed ? "|" : "", #n); \
33 flags &= ~O_##n; \
34 }
35
36 P_FLAG(RDWR);
37 P_FLAG(APPEND);
38 P_FLAG(ASYNC);
39 P_FLAG(CLOEXEC);
40 P_FLAG(CREAT);
41 P_FLAG(DIRECT);
42 P_FLAG(DIRECTORY);
43 P_FLAG(EXCL);
44 P_FLAG(LARGEFILE);
45 P_FLAG(NOFOLLOW);
46 P_FLAG(TMPFILE);
47 P_FLAG(NOATIME);
48 P_FLAG(NOCTTY);
49#ifdef O_NONBLOCK
50 P_FLAG(NONBLOCK);
51#elif O_NDELAY
52 P_FLAG(NDELAY);
53#endif
54#ifdef O_PATH
55 P_FLAG(PATH);
56#endif
57#ifdef O_DSYNC
58 if ((flags & O_SYNC) == O_SYNC)
59 printed += scnprintf(bf + printed, size - printed, "%s%s", printed ? "|" : "", "SYNC");
60 else {
61 P_FLAG(DSYNC);
62 }
63#else
64 P_FLAG(SYNC);
65#endif
66 P_FLAG(TRUNC);
67 P_FLAG(WRONLY);
68#undef P_FLAG
69
70 if (flags)
71 printed += scnprintf(bf + printed, size - printed, "%s%#x", printed ? "|" : "", flags);
72
73 return printed;
74}
75
76size_t syscall_arg__scnprintf_open_flags(char *bf, size_t size, struct syscall_arg *arg)
77{
78 int flags = arg->val;
79
80 if (!(flags & O_CREAT))
81 arg->mask |= 1 << (arg->idx + 1);
82
83 return open__scnprintf_flags(flags, bf, size);
84}
85