1 /* vi: set sw=4 ts=4: */
3 * mode_string implementation for busybox
5 * Copyright (C) 2003 Manuel Novoa III <mjn3@codepoet.org>
7 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
12 #if ( S_ISUID != 04000 ) || ( S_ISGID != 02000 ) || ( S_ISVTX != 01000 ) \
13 || ( S_IRUSR != 00400 ) || ( S_IWUSR != 00200 ) || ( S_IXUSR != 00100 ) \
14 || ( S_IRGRP != 00040 ) || ( S_IWGRP != 00020 ) || ( S_IXGRP != 00010 ) \
15 || ( S_IROTH != 00004 ) || ( S_IWOTH != 00002 ) || ( S_IXOTH != 00001 )
16 #error permission bitflag value assumption(s) violated!
19 #if ( S_IFSOCK!= 0140000 ) || ( S_IFLNK != 0120000 ) \
20 || ( S_IFREG != 0100000 ) || ( S_IFBLK != 0060000 ) \
21 || ( S_IFDIR != 0040000 ) || ( S_IFCHR != 0020000 ) \
22 || ( S_IFIFO != 0010000 )
23 #warning mode type bitflag value assumption(s) violated! falling back to larger version
25 #if (S_IRWXU | S_IRWXG | S_IRWXO | S_ISUID | S_ISGID | S_ISVTX) == 07777
27 #define mode_t unsigned short
30 static const mode_t mode_flags[] = {
31 S_IRUSR, S_IWUSR, S_IXUSR, S_ISUID,
32 S_IRGRP, S_IWGRP, S_IXGRP, S_ISGID,
33 S_IROTH, S_IWOTH, S_IXOTH, S_ISVTX
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. */
40 /* 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. */
42 static const char type_chars[16] ALIGN1 = "?pc?d?b?-?l?s???";
43 /***************************************** 0123456789abcdef */
44 static const char mode_chars[7] ALIGN1 = "rwxSTst";
46 const char* FAST_FUNC bb_mode_string(mode_t mode)
53 *p = type_chars[ (mode >> 12) & 0xf ];
59 if (mode & mode_flags[i+j]) {
64 if (mode & mode_flags[i+j]) {
65 *p = mode_chars[3 + (k & 2) + ((i&8) >> 3)];
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. */
80 /* 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. */
82 static const char type_chars[16] ALIGN1 = "?pc?d?b?-?l?s???";
83 /********************************** 0123456789abcdef */
84 static const char mode_chars[7] ALIGN1 = "rwxSTst";
86 const char* FAST_FUNC bb_mode_string(mode_t mode)
93 *p = type_chars[ (mode >> 12) & 0xf ];
107 if (mode & (010000 >> i)) {
108 *p = mode_chars[3 + (k & 2) + (i == 3)];
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);