diff options
Diffstat (limited to 'lib/filemode.c')
-rw-r--r-- | lib/filemode.c | 45 |
1 files changed, 10 insertions, 35 deletions
diff --git a/lib/filemode.c b/lib/filemode.c index 342ca9ce7..a890100fb 100644 --- a/lib/filemode.c +++ b/lib/filemode.c @@ -38,37 +38,7 @@ #if ! HAVE_DECL_STRMODE -/* Set the 's' and 't' flags in file attributes string CHARS, - according to the file mode BITS. */ - -static void -setst (mode_t bits, char *chars) -{ - if (bits & S_ISUID) - { - if (chars[3] != 'x') - /* Set-uid, but not executable by owner. */ - chars[3] = 'S'; - else - chars[3] = 's'; - } - if (bits & S_ISGID) - { - if (chars[6] != 'x') - /* Set-gid, but not executable by group. */ - chars[6] = 'S'; - else - chars[6] = 's'; - } - if (bits & S_ISVTX) - { - if (chars[9] != 'x') - /* Sticky, but not executable by others. */ - chars[9] = 'T'; - else - chars[9] = 't'; - } -} +# include <string.h> /* Return a character indicating the type of file described by file mode BITS: @@ -135,16 +105,21 @@ strmode (mode_t mode, char *str) str[0] = ftypelet (mode); str[1] = mode & S_IRUSR ? 'r' : '-'; str[2] = mode & S_IWUSR ? 'w' : '-'; - str[3] = mode & S_IXUSR ? 'x' : '-'; + str[3] = (mode & S_ISUID + ? (mode & S_IXUSR ? 's' : 'S') + : (mode & S_IXUSR ? 'x' : '-')); str[4] = mode & S_IRGRP ? 'r' : '-'; str[5] = mode & S_IWGRP ? 'w' : '-'; - str[6] = mode & S_IXGRP ? 'x' : '-'; + str[6] = (mode & S_ISGID + ? (mode & S_IXGRP ? 's' : 'S') + : (mode & S_IXGRP ? 'x' : '-')); str[7] = mode & S_IROTH ? 'r' : '-'; str[8] = mode & S_IWOTH ? 'w' : '-'; - str[9] = mode & S_IXOTH ? 'x' : '-'; + str[9] = (mode & S_ISVTX + ? (mode & S_IXOTH ? 't' : 'T') + : (mode & S_IXOTH ? 'x' : '-')); str[10] = ' '; str[11] = '\0'; - setst (mode, str); } #endif /* ! HAVE_DECL_STRMODE */ |