aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/options.c11
-rw-r--r--src/output.c49
2 files changed, 55 insertions, 5 deletions
diff --git a/src/options.c b/src/options.c
index a2a9221..fc53396 100644
--- a/src/options.c
+++ b/src/options.c
@@ -69,15 +69,16 @@ void usage(char *executable) {
fprintf(stderr, "\n\n--sort-by variants: name | size | time\n");
fprintf(stderr, "\n--format-string: Characters unlike the following are ignored\n");
+ fprintf(stderr, " A - access time\n");
+ fprintf(stderr, " C - change time\n");
+ fprintf(stderr, " g - group id\n");
+ fprintf(stderr, " M - modification time\n");
fprintf(stderr, " n - name\n");
+ fprintf(stderr, " p - permissions\n");
fprintf(stderr, " s - size\n");
- fprintf(stderr, " u - user id\n");
- fprintf(stderr, " g - group id\n");
fprintf(stderr, " T - type\n");
fprintf(stderr, " t - time defined by --time-field (default: modification time)\n");
- fprintf(stderr, " A - access time\n");
- fprintf(stderr, " C - change time\n");
- fprintf(stderr, " M - modification time\n");
+ fprintf(stderr, " u - user id\n");
}
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: