18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: LGPL-2.1 28c2ecf20Sopenharmony_ci#include <sys/types.h> 38c2ecf20Sopenharmony_ci#include <sys/stat.h> 48c2ecf20Sopenharmony_ci#include <unistd.h> 58c2ecf20Sopenharmony_ci 68c2ecf20Sopenharmony_ci/* From include/linux/stat.h */ 78c2ecf20Sopenharmony_ci#ifndef S_IRWXUGO 88c2ecf20Sopenharmony_ci#define S_IRWXUGO (S_IRWXU|S_IRWXG|S_IRWXO) 98c2ecf20Sopenharmony_ci#endif 108c2ecf20Sopenharmony_ci#ifndef S_IALLUGO 118c2ecf20Sopenharmony_ci#define S_IALLUGO (S_ISUID|S_ISGID|S_ISVTX|S_IRWXUGO) 128c2ecf20Sopenharmony_ci#endif 138c2ecf20Sopenharmony_ci#ifndef S_IRUGO 148c2ecf20Sopenharmony_ci#define S_IRUGO (S_IRUSR|S_IRGRP|S_IROTH) 158c2ecf20Sopenharmony_ci#endif 168c2ecf20Sopenharmony_ci#ifndef S_IWUGO 178c2ecf20Sopenharmony_ci#define S_IWUGO (S_IWUSR|S_IWGRP|S_IWOTH) 188c2ecf20Sopenharmony_ci#endif 198c2ecf20Sopenharmony_ci#ifndef S_IXUGO 208c2ecf20Sopenharmony_ci#define S_IXUGO (S_IXUSR|S_IXGRP|S_IXOTH) 218c2ecf20Sopenharmony_ci#endif 228c2ecf20Sopenharmony_ci 238c2ecf20Sopenharmony_cistatic size_t syscall_arg__scnprintf_mode_t(char *bf, size_t size, struct syscall_arg *arg) 248c2ecf20Sopenharmony_ci{ 258c2ecf20Sopenharmony_ci bool show_prefix = arg->show_string_prefix; 268c2ecf20Sopenharmony_ci const char *prefix = "S_"; 278c2ecf20Sopenharmony_ci int printed = 0, mode = arg->val; 288c2ecf20Sopenharmony_ci 298c2ecf20Sopenharmony_ci#define P_MODE(n) \ 308c2ecf20Sopenharmony_ci if ((mode & S_##n) == S_##n) { \ 318c2ecf20Sopenharmony_ci printed += scnprintf(bf + printed, size - printed, "%s%s%s", printed ? "|" : "", show_prefix ? prefix : "", #n); \ 328c2ecf20Sopenharmony_ci mode &= ~S_##n; \ 338c2ecf20Sopenharmony_ci } 348c2ecf20Sopenharmony_ci 358c2ecf20Sopenharmony_ci P_MODE(IALLUGO); 368c2ecf20Sopenharmony_ci P_MODE(IRWXUGO); 378c2ecf20Sopenharmony_ci P_MODE(IRUGO); 388c2ecf20Sopenharmony_ci P_MODE(IWUGO); 398c2ecf20Sopenharmony_ci P_MODE(IXUGO); 408c2ecf20Sopenharmony_ci P_MODE(IFMT); 418c2ecf20Sopenharmony_ci P_MODE(IFSOCK); 428c2ecf20Sopenharmony_ci P_MODE(IFLNK); 438c2ecf20Sopenharmony_ci P_MODE(IFREG); 448c2ecf20Sopenharmony_ci P_MODE(IFBLK); 458c2ecf20Sopenharmony_ci P_MODE(IFDIR); 468c2ecf20Sopenharmony_ci P_MODE(IFCHR); 478c2ecf20Sopenharmony_ci P_MODE(IFIFO); 488c2ecf20Sopenharmony_ci P_MODE(ISUID); 498c2ecf20Sopenharmony_ci P_MODE(ISGID); 508c2ecf20Sopenharmony_ci P_MODE(ISVTX); 518c2ecf20Sopenharmony_ci P_MODE(IRWXU); 528c2ecf20Sopenharmony_ci P_MODE(IRUSR); 538c2ecf20Sopenharmony_ci P_MODE(IWUSR); 548c2ecf20Sopenharmony_ci P_MODE(IXUSR); 558c2ecf20Sopenharmony_ci P_MODE(IRWXG); 568c2ecf20Sopenharmony_ci P_MODE(IRGRP); 578c2ecf20Sopenharmony_ci P_MODE(IWGRP); 588c2ecf20Sopenharmony_ci P_MODE(IXGRP); 598c2ecf20Sopenharmony_ci P_MODE(IRWXO); 608c2ecf20Sopenharmony_ci P_MODE(IROTH); 618c2ecf20Sopenharmony_ci P_MODE(IWOTH); 628c2ecf20Sopenharmony_ci P_MODE(IXOTH); 638c2ecf20Sopenharmony_ci#undef P_MODE 648c2ecf20Sopenharmony_ci 658c2ecf20Sopenharmony_ci if (mode) 668c2ecf20Sopenharmony_ci printed += scnprintf(bf + printed, size - printed, "%s%#x", printed ? "|" : "", mode); 678c2ecf20Sopenharmony_ci 688c2ecf20Sopenharmony_ci return printed; 698c2ecf20Sopenharmony_ci} 708c2ecf20Sopenharmony_ci 718c2ecf20Sopenharmony_ci#define SCA_MODE_T syscall_arg__scnprintf_mode_t 72