libbb: clarify what bb_mode_string() generates

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
Denys Vlasenko 2021-09-17 17:10:38 +02:00
parent 3a65435eaa
commit 6279aec03d
3 changed files with 12 additions and 15 deletions

View File

@ -504,7 +504,7 @@ static NOINLINE unsigned display_single(const struct dnode *dn)
if (opt & OPT_l) { if (opt & OPT_l) {
/* long listing: show mode */ /* long listing: show mode */
char modestr[12]; char modestr[12];
column += printf("%-10s ", (char *) bb_mode_string(modestr, dn->dn_mode)); column += printf("%-10s ", bb_mode_string(modestr, dn->dn_mode));
/* long listing: show number of links */ /* long listing: show number of links */
column += printf("%4lu ", (long) dn->dn_nlink); column += printf("%4lu ", (long) dn->dn_nlink);
/* long listing: show user/group */ /* long listing: show user/group */

View File

@ -440,9 +440,8 @@ void *xmmap_anon(size_t size) FAST_FUNC;
# define cached_pagesize(var) (var) # define cached_pagesize(var) (var)
#endif #endif
/* Generate ls-style "mode string" like "-rwsr-xr-x" or "drwxrwxrwt" */
//TODO: supply a pointer to char[11] buffer (avoid statics)? extern char *bb_mode_string(char buf[11], mode_t mode) FAST_FUNC;
extern char *bb_mode_string(char buf[12], mode_t mode) FAST_FUNC;
extern int is_directory(const char *name, int followLinks) FAST_FUNC; extern int is_directory(const char *name, int followLinks) FAST_FUNC;
enum { /* cp.c, mv.c, install.c depend on these values. CAREFUL when changing them! */ enum { /* cp.c, mv.c, install.c depend on these values. CAREFUL when changing them! */
FILEUTILS_PRESERVE_STATUS = 1 << 0, /* -p */ FILEUTILS_PRESERVE_STATUS = 1 << 0, /* -p */

View File

@ -16,16 +16,18 @@
#error permission bitflag value assumption(s) violated! #error permission bitflag value assumption(s) violated!
#endif #endif
/* Generate ls-style "mode string" like "-rwsr-xr-x" or "drwxrwxrwt" */
#if ( S_IFSOCK!= 0140000 ) || ( S_IFLNK != 0120000 ) \ #if ( S_IFSOCK!= 0140000 ) || ( S_IFLNK != 0120000 ) \
|| ( S_IFREG != 0100000 ) || ( S_IFBLK != 0060000 ) \ || ( S_IFREG != 0100000 ) || ( S_IFBLK != 0060000 ) \
|| ( S_IFDIR != 0040000 ) || ( S_IFCHR != 0020000 ) \ || ( S_IFDIR != 0040000 ) || ( S_IFCHR != 0020000 ) \
|| ( S_IFIFO != 0010000 ) || ( S_IFIFO != 0010000 )
#warning mode type bitflag value assumption(s) violated! falling back to larger version # warning mode type bitflag value assumption(s) violated! falling back to larger version
#if (S_IRWXU | S_IRWXG | S_IRWXO | S_ISUID | S_ISGID | S_ISVTX) == 07777 # if (S_IRWXU | S_IRWXG | S_IRWXO | S_ISUID | S_ISGID | S_ISVTX) == 07777
#undef mode_t # undef mode_t
#define mode_t unsigned short # define mode_t unsigned short
#endif # endif
static const mode_t mode_flags[] ALIGN4 = { static const mode_t mode_flags[] ALIGN4 = {
S_IRUSR, S_IWUSR, S_IXUSR, S_ISUID, S_IRUSR, S_IWUSR, S_IXUSR, S_ISUID,
@ -33,17 +35,13 @@ static const mode_t mode_flags[] ALIGN4 = {
S_IROTH, S_IWOTH, S_IXOTH, S_ISVTX S_IROTH, S_IWOTH, S_IXOTH, S_ISVTX
}; };
/* The static const char arrays below are duplicated for the two cases
* because moving them ahead of the mode_flags declaration cause a text
* size increase with the gcc version I'm using. */
/* The previous version used "0pcCd?bB-?l?s???". However, the '0', 'C', /* The previous version used "0pcCd?bB-?l?s???". However, the '0', 'C',
* and 'B' types don't appear to be available on linux. So I removed them. */ * and 'B' types don't appear to be available on linux. So I removed them. */
static const char type_chars[16] ALIGN1 = "?pc?d?b?-?l?s???"; static const char type_chars[16] ALIGN1 = "?pc?d?b?-?l?s???";
/***************************************** 0123456789abcdef */ /***************************************** 0123456789abcdef */
static const char mode_chars[7] ALIGN1 = "rwxSTst"; static const char mode_chars[7] ALIGN1 = "rwxSTst";
char* FAST_FUNC bb_mode_string(char buf[12], mode_t mode) char* FAST_FUNC bb_mode_string(char buf[11], mode_t mode)
{ {
char *p = buf; char *p = buf;
@ -79,7 +77,7 @@ static const char type_chars[16] ALIGN1 = "?pc?d?b?-?l?s???";
/***************************************** 0123456789abcdef */ /***************************************** 0123456789abcdef */
static const char mode_chars[7] ALIGN1 = "rwxSTst"; static const char mode_chars[7] ALIGN1 = "rwxSTst";
char* FAST_FUNC bb_mode_string(char buf[12], mode_t mode) char* FAST_FUNC bb_mode_string(char buf[11], mode_t mode)
{ {
char *p = buf; char *p = buf;