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) {
/* long listing: show mode */
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 */
column += printf("%4lu ", (long) dn->dn_nlink);
/* long listing: show user/group */

View File

@ -440,9 +440,8 @@ void *xmmap_anon(size_t size) FAST_FUNC;
# define cached_pagesize(var) (var)
#endif
//TODO: supply a pointer to char[11] buffer (avoid statics)?
extern char *bb_mode_string(char buf[12], mode_t mode) FAST_FUNC;
/* Generate ls-style "mode string" like "-rwsr-xr-x" or "drwxrwxrwt" */
extern char *bb_mode_string(char buf[11], mode_t mode) 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! */
FILEUTILS_PRESERVE_STATUS = 1 << 0, /* -p */

View File

@ -16,6 +16,8 @@
#error permission bitflag value assumption(s) violated!
#endif
/* Generate ls-style "mode string" like "-rwsr-xr-x" or "drwxrwxrwt" */
#if ( S_IFSOCK!= 0140000 ) || ( S_IFLNK != 0120000 ) \
|| ( S_IFREG != 0100000 ) || ( S_IFBLK != 0060000 ) \
|| ( S_IFDIR != 0040000 ) || ( S_IFCHR != 0020000 ) \
@ -33,17 +35,13 @@ static const mode_t mode_flags[] ALIGN4 = {
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',
* 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???";
/***************************************** 0123456789abcdef */
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;
@ -79,7 +77,7 @@ static const char type_chars[16] ALIGN1 = "?pc?d?b?-?l?s???";
/***************************************** 0123456789abcdef */
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;