aboutsummaryrefslogtreecommitdiff
path: root/libbb/mode_string.c
diff options
context:
space:
mode:
Diffstat (limited to 'libbb/mode_string.c')
-rw-r--r--libbb/mode_string.c34
1 files changed, 12 insertions, 22 deletions
diff --git a/libbb/mode_string.c b/libbb/mode_string.c
index dc3f9f88c..906c03964 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 && S_IFBLK != 0030000 ) \ 22 || ( S_IFREG != 0100000 ) || ( S_IFBLK != 0060000 && S_IFBLK != 0030000 ) \
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,19 +35,14 @@ 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
46const char* FAST_FUNC bb_mode_string(mode_t mode) 44char* FAST_FUNC bb_mode_string(char buf[11], mode_t mode)
47{ 45{
48 static char buf[12];
49 char *p = buf; 46 char *p = buf;
50 47
51 int i, j, k; 48 int i, j, k;
@@ -67,10 +64,7 @@ const char* FAST_FUNC bb_mode_string(mode_t mode)
67 i += 4; 64 i += 4;
68 } while (i < 12); 65 } while (i < 12);
69 66
70 /* Note: We don't bother with nul termination because bss initialization 67 buf[10] = '\0';
71 * should have taken care of that for us. If the user scribbled in buf
72 * memory, they deserve whatever happens. But we'll at least assert. */
73 assert(buf[10] == 0);
74 68
75 return buf; 69 return buf;
76} 70}
@@ -80,12 +74,11 @@ const char* FAST_FUNC bb_mode_string(mode_t mode)
80/* The previous version used "0pcCd?bB-?l?s???". However, the '0', 'C', 74/* The previous version used "0pcCd?bB-?l?s???". However, the '0', 'C',
81 * and 'B' types don't appear to be available on linux. So I removed them. */ 75 * and 'B' types don't appear to be available on linux. So I removed them. */
82static const char type_chars[16] ALIGN1 = "?pc?d?b?-?l?s???"; 76static const char type_chars[16] ALIGN1 = "?pc?d?b?-?l?s???";
83/********************************** 0123456789abcdef */ 77/***************************************** 0123456789abcdef */
84static const char mode_chars[7] ALIGN1 = "rwxSTst"; 78static const char mode_chars[7] ALIGN1 = "rwxSTst";
85 79
86const char* FAST_FUNC bb_mode_string(mode_t mode) 80char* FAST_FUNC bb_mode_string(char buf[11], mode_t mode)
87{ 81{
88 static char buf[12];
89 char *p = buf; 82 char *p = buf;
90 83
91 int i, j, k, m; 84 int i, j, k, m;
@@ -109,10 +102,7 @@ const char* FAST_FUNC bb_mode_string(mode_t mode)
109 } 102 }
110 } while (i < 3); 103 } while (i < 3);
111 104
112 /* Note: We don't bother with nul termination because bss initialization 105 buf[10] = '\0';
113 * should have taken care of that for us. If the user scribbled in buf
114 * memory, they deserve whatever happens. But we'll at least assert. */
115 assert(buf[10] == 0);
116 106
117 return buf; 107 return buf;
118} 108}