00001 /* 00002 Copyright (C) Andrew Tridgell 1996 00003 Copyright (C) Paul Mackerras 1996 00004 Copyright (C) 2001 by Martin Pool <mbp@samba.org> 00005 00006 This program is free software; you can redistribute it and/or modify 00007 it under the terms of the GNU General Public License as published by 00008 the Free Software Foundation; either version 2 of the License, or 00009 (at your option) any later version. 00010 00011 This program is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 GNU General Public License for more details. 00015 00016 You should have received a copy of the GNU General Public License 00017 along with this program; if not, write to the Free Software 00018 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00019 */ 00020 00021 #include "rsync.h" 00022 00023 /** 00024 * Produce a string representation of Unix mode bits like that used by 00025 * ls(1). 00026 * 00027 * @param buf buffer of at least 11 characters 00028 **/ 00029 void permstring(char *perms, mode_t mode) 00030 { 00031 static const char *perm_map = "rwxrwxrwx"; 00032 int i; 00033 00034 strcpy(perms, "----------"); 00035 00036 for (i=0;i<9;i++) { 00037 if (mode & (1<<i)) perms[9-i] = perm_map[8-i]; 00038 } 00039 00040 /* Handle setuid/sticky bits. You might think the indices are 00041 * off by one, but remember there's a type char at the 00042 * start. */ 00043 if (mode & S_ISUID) 00044 perms[3] = (mode & S_IXUSR) ? 's' : 'S'; 00045 00046 if (mode & S_ISGID) 00047 perms[6] = (mode & S_IXGRP) ? 's' : 'S'; 00048 00049 #ifdef S_ISVTX 00050 if (mode & S_ISVTX) 00051 perms[9] = (mode & S_IXOTH) ? 't' : 'T'; 00052 #endif 00053 00054 if (S_ISLNK(mode)) perms[0] = 'l'; 00055 if (S_ISDIR(mode)) perms[0] = 'd'; 00056 if (S_ISBLK(mode)) perms[0] = 'b'; 00057 if (S_ISCHR(mode)) perms[0] = 'c'; 00058 if (S_ISSOCK(mode)) perms[0] = 's'; 00059 if (S_ISFIFO(mode)) perms[0] = 'p'; 00060 } 00061 00062