1 /* 2 * File metadata formatting. 3 * 4 * Copyright (C) 2019, 2021 Paul Boddie <paul@boddie.org.uk> 5 * 6 * This program is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU General Public License as 8 * published by the Free Software Foundation; either version 2 of 9 * the License, or (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., 51 Franklin Street, Fifth Floor, 19 * Boston, MA 02110-1301, USA 20 */ 21 22 #include "format.h" 23 24 25 26 /* Return the permissions of an object as a string. */ 27 28 char *get_permission_string(uint16_t permissions) 29 { 30 static char s[11] = "---------\0"; 31 static char letters[] = "rwx"; 32 int i, letter; 33 uint16_t selector = 0400; 34 35 for (i = 0, letter = 0; i < 10; i++, letter = (letter + 1) % 3, selector >>= 1) 36 s[i] = permissions & selector ? letters[letter] : '-'; 37 38 return s; 39 }