summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/ChangeLog5
-rw-r--r--lib/filemode.c45
2 files changed, 15 insertions, 35 deletions
diff --git a/lib/ChangeLog b/lib/ChangeLog
index 35b05686f..efa92ee5e 100644
--- a/lib/ChangeLog
+++ b/lib/ChangeLog
@@ -1,5 +1,10 @@
2006-05-22 Paul Eggert <eggert@cs.ucla.edu>
+ * filemode.c (setst): Remove.
+ (strmode): Rewrite to avoid setst. This makes the code shorter,
+ (arguably) clearer, and the generated code is a bit smaller on my
+ Debian GNU/Linux stable x86 host.
+
Import from gnulib.
* verify.h: Document the internals better. Most of this change
was written by Bruno Haible.
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 */