~mmach/netext73/busybox

« back to all changes in this revision

Viewing changes to libbb/mode_string.c

  • Committer: mmach
  • Date: 2022-08-22 15:28:31 UTC
  • Revision ID: netbit73@gmail.com-20220822152831-vrsxgw6c75b03ujx
1.35.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
#error permission bitflag value assumption(s) violated!
17
17
#endif
18
18
 
 
19
/* Generate ls-style "mode string" like "-rwsr-xr-x" or "drwxrwxrwt" */
 
20
 
19
21
#if ( S_IFSOCK!= 0140000 ) || ( S_IFLNK != 0120000 ) \
20
22
 || ( S_IFREG != 0100000 ) || ( S_IFBLK != 0060000 ) \
21
23
 || ( S_IFDIR != 0040000 ) || ( S_IFCHR != 0020000 ) \
22
24
 || ( S_IFIFO != 0010000 )
23
 
#warning mode type bitflag value assumption(s) violated! falling back to larger version
24
 
 
25
 
#if (S_IRWXU | S_IRWXG | S_IRWXO | S_ISUID | S_ISGID | S_ISVTX) == 07777
26
 
#undef mode_t
27
 
#define mode_t unsigned short
28
 
#endif
29
 
 
30
 
static const mode_t mode_flags[] = {
 
25
# warning mode type bitflag value assumption(s) violated! falling back to larger version
 
26
 
 
27
# if (S_IRWXU | S_IRWXG | S_IRWXO | S_ISUID | S_ISGID | S_ISVTX) == 07777
 
28
#  undef mode_t
 
29
#  define mode_t unsigned short
 
30
# endif
 
31
 
 
32
static const mode_t mode_flags[] ALIGN4 = {
31
33
        S_IRUSR, S_IWUSR, S_IXUSR, S_ISUID,
32
34
        S_IRGRP, S_IWGRP, S_IXGRP, S_ISGID,
33
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
38
/* The previous version used "0pcCd?bB-?l?s???".  However, the '0', 'C',
41
39
 * and 'B' types don't appear to be available on linux.  So I removed them. */
42
40
static const char type_chars[16] ALIGN1 = "?pc?d?b?-?l?s???";
43
41
/***************************************** 0123456789abcdef */
44
42
static const char mode_chars[7] ALIGN1 = "rwxSTst";
45
43
 
46
 
const char* FAST_FUNC bb_mode_string(mode_t mode)
 
44
char* FAST_FUNC bb_mode_string(char buf[11], mode_t mode)
47
45
{
48
 
        static char buf[12];
49
46
        char *p = buf;
50
47
 
51
48
        int i, j, k;
67
64
                i += 4;
68
65
        } while (i < 12);
69
66
 
70
 
        /* Note: We don't bother with nul termination because bss initialization
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);
 
67
        buf[10] = '\0';
74
68
 
75
69
        return buf;
76
70
}
80
74
/* The previous version used "0pcCd?bB-?l?s???".  However, the '0', 'C',
81
75
 * and 'B' types don't appear to be available on linux.  So I removed them. */
82
76
static const char type_chars[16] ALIGN1 = "?pc?d?b?-?l?s???";
83
 
/********************************** 0123456789abcdef */
 
77
/***************************************** 0123456789abcdef */
84
78
static const char mode_chars[7] ALIGN1 = "rwxSTst";
85
79
 
86
 
const char* FAST_FUNC bb_mode_string(mode_t mode)
 
80
char* FAST_FUNC bb_mode_string(char buf[11], mode_t mode)
87
81
{
88
 
        static char buf[12];
89
82
        char *p = buf;
90
83
 
91
84
        int i, j, k, m;
109
102
                }
110
103
        } while (i < 3);
111
104
 
112
 
        /* Note: We don't bother with nul termination because bss initialization
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);
 
105
        buf[10] = '\0';
116
106
 
117
107
        return buf;
118
108
}