aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--coreutils/ls.c2
-rw-r--r--include/libbb.h5
-rw-r--r--libbb/mode_string.c20
3 files changed, 12 insertions, 15 deletions
diff --git a/coreutils/ls.c b/coreutils/ls.c
index 9a1264e65..48f5eb482 100644
--- a/coreutils/ls.c
+++ b/coreutils/ls.c
@@ -504,7 +504,7 @@ static NOINLINE unsigned display_single(const struct dnode *dn)
504 if (opt & OPT_l) { 504 if (opt & OPT_l) {
505 /* long listing: show mode */ 505 /* long listing: show mode */
506 char modestr[12]; 506 char modestr[12];
507 column += printf("%-10s ", (char *) bb_mode_string(modestr, dn->dn_mode)); 507 column += printf("%-10s ", bb_mode_string(modestr, dn->dn_mode));
508 /* long listing: show number of links */ 508 /* long listing: show number of links */
509 column += printf("%4lu ", (long) dn->dn_nlink); 509 column += printf("%4lu ", (long) dn->dn_nlink);
510 /* long listing: show user/group */ 510 /* long listing: show user/group */
diff --git a/include/libbb.h b/include/libbb.h
index b0312e5d4..dfcaa05ec 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -440,9 +440,8 @@ void *xmmap_anon(size_t size) FAST_FUNC;
440# define cached_pagesize(var) (var) 440# define cached_pagesize(var) (var)
441#endif 441#endif
442 442
443 443/* Generate ls-style "mode string" like "-rwsr-xr-x" or "drwxrwxrwt" */
444//TODO: supply a pointer to char[11] buffer (avoid statics)? 444extern char *bb_mode_string(char buf[11], mode_t mode) FAST_FUNC;
445extern char *bb_mode_string(char buf[12], mode_t mode) FAST_FUNC;
446extern int is_directory(const char *name, int followLinks) FAST_FUNC; 445extern int is_directory(const char *name, int followLinks) FAST_FUNC;
447enum { /* cp.c, mv.c, install.c depend on these values. CAREFUL when changing them! */ 446enum { /* cp.c, mv.c, install.c depend on these values. CAREFUL when changing them! */
448 FILEUTILS_PRESERVE_STATUS = 1 << 0, /* -p */ 447 FILEUTILS_PRESERVE_STATUS = 1 << 0, /* -p */
diff --git a/libbb/mode_string.c b/libbb/mode_string.c
index 8c12b4684..52abe66f7 100644
--- a/libbb/mode_string.c
+++ b/libbb/mode_string.c
@@ -16,16 +16,18 @@
16#error permission bitflag value assumption(s) violated! 16#error permission bitflag value assumption(s) violated!
17#endif 17#endif
18 18
19/* Generate ls-style "mode string" like "-rwsr-xr-x" or "drwxrwxrwt" */
20
19#if ( S_IFSOCK!= 0140000 ) || ( S_IFLNK != 0120000 ) \ 21#if ( S_IFSOCK!= 0140000 ) || ( S_IFLNK != 0120000 ) \
20 || ( S_IFREG != 0100000 ) || ( S_IFBLK != 0060000 ) \ 22 || ( S_IFREG != 0100000 ) || ( S_IFBLK != 0060000 ) \
21 || ( S_IFDIR != 0040000 ) || ( S_IFCHR != 0020000 ) \ 23 || ( S_IFDIR != 0040000 ) || ( S_IFCHR != 0020000 ) \
22 || ( S_IFIFO != 0010000 ) 24 || ( S_IFIFO != 0010000 )
23#warning mode type bitflag value assumption(s) violated! falling back to larger version 25# warning mode type bitflag value assumption(s) violated! falling back to larger version
24 26
25#if (S_IRWXU | S_IRWXG | S_IRWXO | S_ISUID | S_ISGID | S_ISVTX) == 07777 27# if (S_IRWXU | S_IRWXG | S_IRWXO | S_ISUID | S_ISGID | S_ISVTX) == 07777
26#undef mode_t 28# undef mode_t
27#define mode_t unsigned short 29# define mode_t unsigned short
28#endif 30# endif
29 31
30static const mode_t mode_flags[] ALIGN4 = { 32static const mode_t mode_flags[] ALIGN4 = {
31 S_IRUSR, S_IWUSR, S_IXUSR, S_ISUID, 33 S_IRUSR, S_IWUSR, S_IXUSR, S_ISUID,
@@ -33,17 +35,13 @@ static const mode_t mode_flags[] ALIGN4 = {
33 S_IROTH, S_IWOTH, S_IXOTH, S_ISVTX 35 S_IROTH, S_IWOTH, S_IXOTH, S_ISVTX
34}; 36};
35 37
36/* The static const char arrays below are duplicated for the two cases
37 * because moving them ahead of the mode_flags declaration cause a text
38 * size increase with the gcc version I'm using. */
39
40/* The previous version used "0pcCd?bB-?l?s???". However, the '0', 'C', 38/* The previous version used "0pcCd?bB-?l?s???". However, the '0', 'C',
41 * and 'B' types don't appear to be available on linux. So I removed them. */ 39 * and 'B' types don't appear to be available on linux. So I removed them. */
42static const char type_chars[16] ALIGN1 = "?pc?d?b?-?l?s???"; 40static const char type_chars[16] ALIGN1 = "?pc?d?b?-?l?s???";
43/***************************************** 0123456789abcdef */ 41/***************************************** 0123456789abcdef */
44static const char mode_chars[7] ALIGN1 = "rwxSTst"; 42static const char mode_chars[7] ALIGN1 = "rwxSTst";
45 43
46char* FAST_FUNC bb_mode_string(char buf[12], mode_t mode) 44char* FAST_FUNC bb_mode_string(char buf[11], mode_t mode)
47{ 45{
48 char *p = buf; 46 char *p = buf;
49 47
@@ -79,7 +77,7 @@ static const char type_chars[16] ALIGN1 = "?pc?d?b?-?l?s???";
79/***************************************** 0123456789abcdef */ 77/***************************************** 0123456789abcdef */
80static const char mode_chars[7] ALIGN1 = "rwxSTst"; 78static const char mode_chars[7] ALIGN1 = "rwxSTst";
81 79
82char* FAST_FUNC bb_mode_string(char buf[12], mode_t mode) 80char* FAST_FUNC bb_mode_string(char buf[11], mode_t mode)
83{ 81{
84 char *p = buf; 82 char *p = buf;
85 83