From 1154e2aacf1539936ca2d45a14f923b63d288d36 Mon Sep 17 00:00:00 2001 From: Thorsten Töpper Date: Sat, 5 Jul 2025 17:52:42 +0200 Subject: output: format string: permissions --- src/output.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) (limited to 'src/output.c') diff --git a/src/output.c b/src/output.c index 1e08f2d..35500b0 100644 --- a/src/output.c +++ b/src/output.c @@ -28,6 +28,7 @@ #define out_print_uid(x) printf(" %4u ", x->ln_stat.st_gid) #define out_print_gid(x) printf(" %4u ", x->ln_stat.st_uid) +void out_print_permissions(struct list_node *ptr); void out_print_size(struct list_node *ptr); void out_print_time(time_t tv); void out_print_time_by_option(struct list_node *ptr); @@ -157,6 +158,51 @@ inline void out_print_type(struct list_node *ptr) { printf(" %-12s ", entry); } +inline void out_print_permissions(struct list_node *ptr) { + mode_t mode = 0; + /* User permissions */ + if (ptr->ln_stat.st_mode & S_IXUSR) { + mode |= S_IXUSR; + } + if (ptr->ln_stat.st_mode & S_IWUSR) { + mode |= S_IWUSR; + } + if (ptr->ln_stat.st_mode & S_IRUSR) { + mode |= S_IRUSR; + } + /* Group permissions */ + if (ptr->ln_stat.st_mode & S_IXGRP) { + mode |= S_IXGRP; + } + if (ptr->ln_stat.st_mode & S_IWGRP) { + mode |= S_IWGRP; + } + if (ptr->ln_stat.st_mode & S_IRGRP) { + mode |= S_IRGRP; + } + /* Other permissions */ + if (ptr->ln_stat.st_mode & S_IXOTH) { + mode |= S_IXOTH; + } + if (ptr->ln_stat.st_mode & S_IWOTH) { + mode |= S_IWOTH; + } + if (ptr->ln_stat.st_mode & S_IROTH) { + mode |= S_IROTH; + } + /* special bits */ + if (ptr->ln_stat.st_mode & S_ISVTX) { + mode |= S_ISVTX; + } + if (ptr->ln_stat.st_mode & S_ISGID) { + mode |= S_ISGID; + } + if (ptr->ln_stat.st_mode & S_ISUID) { + mode |= S_ISUID; + } + printf(" %4o ", mode); +} + /* === END OF FORMATTING FUNCTIONS === */ @@ -269,6 +315,9 @@ void print_list_formatted(const char *format, struct list_head *list) { case 'g': out_print_gid(ptr); break; + case 'p': + out_print_permissions(ptr); + break; case ' ': /* just ignore this without warning */ break; default: -- cgit v1.2.3-70-g09d2