aboutsummaryrefslogtreecommitdiff
path: root/src/output.c
diff options
context:
space:
mode:
authorThorsten Töpper <atsutane@freethoughts.de>2025-07-05 17:52:42 +0200
committerThorsten Töpper <atsutane@freethoughts.de>2025-07-05 17:52:42 +0200
commit1154e2aacf1539936ca2d45a14f923b63d288d36 (patch)
tree39b15e9596317b9c94efad4cb0071e1352c38ca8 /src/output.c
parent1efbe4cf958b8fcd590bd887652d1afd9d100c20 (diff)
downloaddir_monitor-1154e2aacf1539936ca2d45a14f923b63d288d36.tar.gz
dir_monitor-1154e2aacf1539936ca2d45a14f923b63d288d36.tar.bz2
output: format string: permissions
Diffstat (limited to 'src/output.c')
-rw-r--r--src/output.c49
1 files changed, 49 insertions, 0 deletions
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: