aboutsummaryrefslogtreecommitdiff
path: root/toys/pending
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/pending
parentb4a86ac3ab6a248b5345557a4c9f1efba7695246 (diff)
downloadtoybox-5a221e6b84e9eab02e24ca541530e28eb7cfddac.tar.gz
Add library function for the file permission formatting in ls and stat
Diffstat (limited to 'toys/pending')
-rw-r--r--toys/pending/stat.c23
1 files changed, 2 insertions, 21 deletions
diff --git a/toys/pending/stat.c b/toys/pending/stat.c
index 4ce2548b..9710acff 100644
--- a/toys/pending/stat.c
+++ b/toys/pending/stat.c
@@ -50,7 +50,7 @@ config STAT
GLOBALS(
char *fmt;
- char *access_str;
+ char access_str[11];
char *file_type;
struct passwd *user_name;
struct group *group_name;
@@ -86,25 +86,6 @@ static char * check_type_file(mode_t mode, size_t size)
if (S_ISSOCK(mode)) return "socket";
}
-static char * get_access_str(unsigned long permission, mode_t mode)
-{
- static char access_string[11];
- char *s = access_string;
- char *rwx[] = {"---", "--x", "-w-", "-wx",
- "r--", "r-x", "rw-", "rwx"};
-
- if (S_ISDIR(mode)) *s = 'd';
- else *s = '-';
-
- for (s += 7; s > access_string; s-=3) {
- memcpy(s, rwx[permission & 7], 3);
- permission >>= 3;
- }
-
- access_string[10] = '\0';
- return access_string;
-}
-
static char * date_stat_format(time_t time)
{
static char buf[36];
@@ -252,7 +233,7 @@ void stat_main(void)
TT.user_name = getpwuid(TT.toystat->st_uid);
TT.group_name = getgrgid(TT.toystat->st_gid);
// function to get access in human readable format
- TT.access_str = get_access_str(TT.toystat->st_mode & ~S_IFMT, TT.toystat->st_mode);
+ format_mode(&TT.access_str, TT.toystat->st_mode);
} else do_statfs(*toys.optargs);
print_stat_format(fmts[!flag_c*flag_f+flag_c], flag_f);
}