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 static size_t syscall_arg__scnprintf_open_flags(char *bf, size_t size, 18 struct syscall_arg *arg) 19 { 20 int printed = 0, flags = arg->val; 21 22 if (!(flags & O_CREAT)) 23 arg->mask |= 1 << (arg->idx + 1); /* Mask the mode parm */ 24 25 if (flags == 0) 26 return scnprintf(bf, size, "RDONLY"); 27 #define P_FLAG(n) \ 28 if (flags & O_##n) { \ 29 printed += scnprintf(bf + printed, size - printed, "%s%s", printed ? "|" : "", #n); \ 30 flags &= ~O_##n; \ 31 } 32 33 P_FLAG(APPEND); 34 P_FLAG(ASYNC); 35 P_FLAG(CLOEXEC); 36 P_FLAG(CREAT); 37 P_FLAG(DIRECT); 38 P_FLAG(DIRECTORY); 39 P_FLAG(EXCL); 40 P_FLAG(LARGEFILE); 41 P_FLAG(NOATIME); 42 P_FLAG(NOCTTY); 43 #ifdef O_NONBLOCK 44 P_FLAG(NONBLOCK); 45 #elif O_NDELAY 46 P_FLAG(NDELAY); 47 #endif 48 #ifdef O_PATH 49 P_FLAG(PATH); 50 #endif 51 P_FLAG(RDWR); 52 #ifdef O_DSYNC 53 if ((flags & O_SYNC) == O_SYNC) 54 printed += scnprintf(bf + printed, size - printed, "%s%s", printed ? "|" : "", "SYNC"); 55 else { 56 P_FLAG(DSYNC); 57 } 58 #else 59 P_FLAG(SYNC); 60 #endif 61 P_FLAG(TRUNC); 62 P_FLAG(WRONLY); 63 #undef P_FLAG 64 65 if (flags) 66 printed += scnprintf(bf + printed, size - printed, "%s%#x", printed ? "|" : "", flags); 67 68 return printed; 69 } 70 71 #define SCA_OPEN_FLAGS syscall_arg__scnprintf_open_flags 72