2 * A single utility routine.
4 * Copyright (C) 1996 Andrew Tridgell
5 * Copyright (C) 1996 Paul Mackerras
6 * Copyright (C) 2001 Martin Pool <mbp@samba.org>
7 * Copyright (C) 2003, 2006 Wayne Davison
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 3 as
11 * published by the Free Software Foundation.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, visit the http://fsf.org website.
24 /* Produce a string representation of Unix mode bits like that used by ls(1).
25 * The "buf" buffer must be at least 11 characters. */
26 void permstring(char *perms, mode_t mode)
28 static const char *perm_map = "rwxrwxrwx";
31 strlcpy(perms, "----------", 11);
33 for (i = 0; i < 9; i++) {
35 perms[9-i] = perm_map[8-i];
38 /* Handle setuid/sticky bits. You might think the indices are
39 * off by one, but remember there's a type char at the
42 perms[3] = (mode & S_IXUSR) ? 's' : 'S';
45 perms[6] = (mode & S_IXGRP) ? 's' : 'S';
49 perms[9] = (mode & S_IXOTH) ? 't' : 'T';
54 else if (S_ISLNK(mode))
56 else if (S_ISBLK(mode))
58 else if (S_ISCHR(mode))
60 else if (S_ISSOCK(mode))
62 else if (S_ISFIFO(mode))