aboutsummaryrefslogtreecommitdiff
path: root/toys/posix/ls.c
diff options
context:
space:
mode:
authorFelix Janda <felix.janda@posteo.de>2013-04-22 22:29:43 +0200
committerFelix Janda <felix.janda@posteo.de>2013-04-22 22:29:43 +0200
commit5a221e6b84e9eab02e24ca541530e28eb7cfddac (patch)
treeffa01832e66ea605e40c5e6c730b22b6088b121d /toys/posix/ls.c
parentb4a86ac3ab6a248b5345557a4c9f1efba7695246 (diff)
downloadtoybox-5a221e6b84e9eab02e24ca541530e28eb7cfddac.tar.gz
Add library function for the file permission formatting in ls and stat
Diffstat (limited to 'toys/posix/ls.c')
-rw-r--r--toys/posix/ls.c23
1 files changed, 2 insertions, 21 deletions
diff --git a/toys/posix/ls.c b/toys/posix/ls.c
index 5982adfe..76fb7947 100644
--- a/toys/posix/ls.c
+++ b/toys/posix/ls.c
@@ -335,28 +335,9 @@ static void listfiles(int dirfd, struct dirtree *indir)
if (flags & (FLAG_l|FLAG_o|FLAG_n|FLAG_g)) {
struct tm *tm;
- char perm[11], thyme[64], c, d, *usr, *upad, *grp, *grpad;
- int i, bit;
-
- perm[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] : '-';
- perm[9-i] = c;
- }
+ char perm[11], thyme[64], *usr, *upad, *grp, *grpad;
- 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 = '-';
- *perm = c;
+ format_mode(&perm, mode);
tm = localtime(&(st->st_mtime));
strftime(thyme, sizeof(thyme), "%F %H:%M", tm);