xref: /openbmc/linux/tools/perf/trace/beauty/mode_t.c (revision cfbb9be8)
1 // SPDX-License-Identifier: GPL-2.0
2 #include <sys/types.h>
3 #include <sys/stat.h>
4 #include <unistd.h>
5 
6 /* From include/linux/stat.h */
7 #ifndef S_IRWXUGO
8 #define S_IRWXUGO	(S_IRWXU|S_IRWXG|S_IRWXO)
9 #endif
10 #ifndef S_IALLUGO
11 #define S_IALLUGO	(S_ISUID|S_ISGID|S_ISVTX|S_IRWXUGO)
12 #endif
13 #ifndef S_IRUGO
14 #define S_IRUGO         (S_IRUSR|S_IRGRP|S_IROTH)
15 #endif
16 #ifndef S_IWUGO
17 #define S_IWUGO         (S_IWUSR|S_IWGRP|S_IWOTH)
18 #endif
19 #ifndef S_IXUGO
20 #define S_IXUGO         (S_IXUSR|S_IXGRP|S_IXOTH)
21 #endif
22 
23 static size_t syscall_arg__scnprintf_mode_t(char *bf, size_t size, struct syscall_arg *arg)
24 {
25 	int printed = 0, mode = arg->val;
26 
27 #define	P_MODE(n) \
28 	if ((mode & S_##n) == S_##n) { \
29 		printed += scnprintf(bf + printed, size - printed, "%s%s", printed ? "|" : "", #n); \
30 		mode &= ~S_##n; \
31 	}
32 
33 	P_MODE(IALLUGO);
34 	P_MODE(IRWXUGO);
35 	P_MODE(IRUGO);
36 	P_MODE(IWUGO);
37 	P_MODE(IXUGO);
38 	P_MODE(IFMT);
39 	P_MODE(IFSOCK);
40 	P_MODE(IFLNK);
41 	P_MODE(IFREG);
42 	P_MODE(IFBLK);
43 	P_MODE(IFDIR);
44 	P_MODE(IFCHR);
45 	P_MODE(IFIFO);
46 	P_MODE(ISUID);
47 	P_MODE(ISGID);
48 	P_MODE(ISVTX);
49 	P_MODE(IRWXU);
50 	P_MODE(IRUSR);
51 	P_MODE(IWUSR);
52 	P_MODE(IXUSR);
53 	P_MODE(IRWXG);
54 	P_MODE(IRGRP);
55 	P_MODE(IWGRP);
56 	P_MODE(IXGRP);
57 	P_MODE(IRWXO);
58 	P_MODE(IROTH);
59 	P_MODE(IWOTH);
60 	P_MODE(IXOTH);
61 #undef P_MODE
62 
63 	if (mode)
64 		printed += scnprintf(bf + printed, size - printed, "%s%#x", printed ? "|" : "", mode);
65 
66 	return printed;
67 }
68 
69 #define SCA_MODE_T syscall_arg__scnprintf_mode_t
70