]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
* filemode.c (setst): Remove.
authorPaul Eggert <eggert@cs.ucla.edu>
Mon, 22 May 2006 20:11:45 +0000 (20:11 +0000)
committerPaul Eggert <eggert@cs.ucla.edu>
Mon, 22 May 2006 20:11:45 +0000 (20:11 +0000)
(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.

lib/ChangeLog
lib/filemode.c

index 35b05686f505923eb8ffa0b9922b81b1bc4b949e..efa92ee5e4901b444ddf1a684526f4819d81f4d9 100644 (file)
@@ -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.
index 342ca9ce701118f683034ac04e7b516fd596e2cf..a890100fbaa9714f6ab6b6cf4fb6a44706b75138 100644 (file)
 
 #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 */