Changed the mode arg from an int to a mode_t.
[rsync/rsync.git] / lib / permstring.c
index 4275dfe..3834b7a 100644 (file)
@@ -18,7 +18,7 @@
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */
 
-#include <sys/stat.h>
+#include "rsync.h"
 
 /**
  * Produce a string representation of Unix mode bits like that used by
@@ -26,8 +26,7 @@
  *
  * @param buf buffer of at least 11 characters
  **/
-void permstring(char *perms,
-               int mode)
+void permstring(char *perms, mode_t mode)
 {
        static const char *perm_map = "rwxrwxrwx";
        int i;
@@ -37,6 +36,21 @@ void permstring(char *perms,
        for (i=0;i<9;i++) {
                if (mode & (1<<i)) perms[9-i] = perm_map[8-i];
        }
+
+       /* Handle setuid/sticky bits.  You might think the indices are
+        * off by one, but remember there's a type char at the
+        * start.  */
+       if (mode & S_ISUID)
+               perms[3] = (mode & S_IXUSR) ? 's' : 'S';
+
+       if (mode & S_ISGID)
+               perms[6] = (mode & S_IXGRP) ? 's' : 'S';
+       
+#ifdef S_ISVTX
+       if (mode & S_ISVTX)
+               perms[9] = (mode & S_IXOTH) ? 't' : 'T';
+#endif
+               
        if (S_ISLNK(mode)) perms[0] = 'l';
        if (S_ISDIR(mode)) perms[0] = 'd';
        if (S_ISBLK(mode)) perms[0] = 'b';