Mercurial > hg > toybox
diff toys/pending/stat.c @ 885:beb32d780164
Add library function for the file permission formatting in ls and stat
author | Felix Janda <felix.janda@posteo.de> |
---|---|
date | Mon, 22 Apr 2013 22:29:43 +0200 |
parents | 793972c94560 |
children | 6bb5c8ace240 |
line wrap: on
line diff
--- a/toys/pending/stat.c Sat Apr 27 00:57:11 2013 -0500 +++ b/toys/pending/stat.c Mon Apr 22 22:29:43 2013 +0200 @@ -50,7 +50,7 @@ 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 @@ 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 @@ 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); }