bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

filemode.c minor cleanup


From: Paul Eggert
Subject: filemode.c minor cleanup
Date: Mon, 22 May 2006 13:13:06 -0700
User-agent: Gnus/5.1008 (Gnus v5.10.8) Emacs/21.4 (gnu/linux)

I installed this:

2006-05-22  Paul Eggert  <address@hidden>

        * lib/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.

--- lib/filemode.c      17 Apr 2006 23:21:14 -0000      1.17
+++ lib/filemode.c      22 May 2006 20:11:45 -0000      1.18
@@ -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 */




reply via email to

[Prev in Thread] Current Thread [Next in Thread]