aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/lib.c26
-rw-r--r--lib/lib.h1
2 files changed, 27 insertions, 0 deletions
diff --git a/lib/lib.c b/lib/lib.c
index 4d8e23a4..b89f2db8 100644
--- a/lib/lib.c
+++ b/lib/lib.c
@@ -1176,6 +1176,32 @@ barf:
error_exit("bad mode '%s'", modestr);
}
+// Format a mode for ls and stat
+void format_mode(char (*buf)[11], mode_t mode)
+{
+ char c, d;
+ int i, bit;
+
+ (*buf)[10]=0;
+ for (i=0; i<9; i++) {
+ bit = mode & (1<<i);
+ c = i%3;
+ if (!c && (mode & (1<<((d=i/3)+9)))) {
+ c = "tss"[d];
+ if (!bit) c &= ~0x20;
+ } else c = bit ? "xwr"[c] : '-';
+ (*buf)[9-i] = c;
+ }
+
+ if (S_ISDIR(mode)) c = 'd';
+ else if (S_ISBLK(mode)) c = 'b';
+ else if (S_ISCHR(mode)) c = 'c';
+ else if (S_ISLNK(mode)) c = 'l';
+ else if (S_ISFIFO(mode)) c = 'p';
+ else if (S_ISSOCK(mode)) c = 's';
+ else c = '-';
+ **buf = c;
+}
char* make_human_readable(unsigned long long size, unsigned long unit)
{
diff --git a/lib/lib.h b/lib/lib.h
index ab858f90..a4da031c 100644
--- a/lib/lib.h
+++ b/lib/lib.h
@@ -178,6 +178,7 @@ int sig_to_num(char *pidstr);
char *num_to_sig(int sig);
mode_t string_to_mode(char *mode_str, mode_t base);
+void format_mode(char (*buf)[11], mode_t mode);
// password helper functions
int read_password(char * buff, int buflen, char* mesg);