Commit | Line | Data |
---|---|---|
740819ef MP |
1 | /* |
2 | Copyright (C) Andrew Tridgell 1996 | |
3 | Copyright (C) Paul Mackerras 1996 | |
4 | Copyright (C) 2001 by Martin Pool <mbp@samba.org> | |
5 | ||
6 | This program is free software; you can redistribute it and/or modify | |
7 | it under the terms of the GNU General Public License as published by | |
8 | the Free Software Foundation; either version 2 of the License, or | |
9 | (at your option) any later version. | |
10 | ||
11 | This program is distributed in the hope that it will be useful, | |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | GNU General Public License for more details. | |
15 | ||
16 | You should have received a copy of the GNU General Public License | |
17 | along with this program; if not, write to the Free Software | |
18 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
19 | */ | |
20 | ||
0e916c60 | 21 | #include "rsync.h" |
740819ef MP |
22 | |
23 | /** | |
24 | * Produce a string representation of Unix mode bits like that used by | |
25 | * ls(1). | |
26 | * | |
27 | * @param buf buffer of at least 11 characters | |
28 | **/ | |
29 | void permstring(char *perms, | |
30 | int mode) | |
31 | { | |
32 | static const char *perm_map = "rwxrwxrwx"; | |
33 | int i; | |
34 | ||
35 | strcpy(perms, "----------"); | |
36 | ||
37 | for (i=0;i<9;i++) { | |
38 | if (mode & (1<<i)) perms[9-i] = perm_map[8-i]; | |
39 | } | |
087173c8 MP |
40 | |
41 | /* Handle setuid/sticky bits. You might think the indices are | |
42 | * off by one, but remember there's a type char at the | |
43 | * start. */ | |
44 | if (mode & S_ISUID) | |
45 | perms[3] = (mode & S_IXUSR) ? 's' : 'S'; | |
46 | ||
47 | if (mode & S_ISGID) | |
48 | perms[6] = (mode & S_IXGRP) ? 's' : 'S'; | |
49 | ||
7ea84b68 | 50 | #ifdef S_ISVTX |
087173c8 MP |
51 | if (mode & S_ISVTX) |
52 | perms[9] = (mode & S_IXOTH) ? 't' : 'T'; | |
7ea84b68 | 53 | #endif |
087173c8 | 54 | |
740819ef MP |
55 | if (S_ISLNK(mode)) perms[0] = 'l'; |
56 | if (S_ISDIR(mode)) perms[0] = 'd'; | |
57 | if (S_ISBLK(mode)) perms[0] = 'b'; | |
58 | if (S_ISCHR(mode)) perms[0] = 'c'; | |
59 | if (S_ISSOCK(mode)) perms[0] = 's'; | |
60 | if (S_ISFIFO(mode)) perms[0] = 'p'; | |
61 | } | |
62 | ||
63 |