Just include rsync.h rather than all the individual headers.
[rsync/rsync.git] / lib / permstring.c
index 4275dfe..a253f07 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
@@ -37,6 +37,19 @@ 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';
+       
+       if (mode & S_ISVTX)
+               perms[9] = (mode & S_IXOTH) ? 't' : 'T';
+               
        if (S_ISLNK(mode)) perms[0] = 'l';
        if (S_ISDIR(mode)) perms[0] = 'd';
        if (S_ISBLK(mode)) perms[0] = 'b';