paul@181 | 1 | /* |
paul@181 | 2 | * File metadata formatting. |
paul@181 | 3 | * |
paul@226 | 4 | * Copyright (C) 2019, 2021 Paul Boddie <paul@boddie.org.uk> |
paul@181 | 5 | * |
paul@181 | 6 | * This program is free software; you can redistribute it and/or |
paul@181 | 7 | * modify it under the terms of the GNU General Public License as |
paul@181 | 8 | * published by the Free Software Foundation; either version 2 of |
paul@181 | 9 | * the License, or (at your option) any later version. |
paul@181 | 10 | * |
paul@181 | 11 | * This program is distributed in the hope that it will be useful, |
paul@181 | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
paul@181 | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
paul@181 | 14 | * GNU General Public License for more details. |
paul@181 | 15 | * |
paul@181 | 16 | * You should have received a copy of the GNU General Public License |
paul@181 | 17 | * along with this program; if not, write to the Free Software |
paul@181 | 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, |
paul@181 | 19 | * Boston, MA 02110-1301, USA |
paul@181 | 20 | */ |
paul@181 | 21 | |
paul@181 | 22 | #include "format.h" |
paul@181 | 23 | |
paul@181 | 24 | |
paul@181 | 25 | |
paul@181 | 26 | /* Return the permissions of an object as a string. */ |
paul@181 | 27 | |
paul@181 | 28 | char *get_permission_string(uint16_t permissions) |
paul@181 | 29 | { |
paul@226 | 30 | static char s[11] = "---------\0"; |
paul@181 | 31 | static char letters[] = "rwx"; |
paul@181 | 32 | int i, letter; |
paul@181 | 33 | uint16_t selector = 0400; |
paul@181 | 34 | |
paul@226 | 35 | for (i = 0, letter = 0; i < 10; i++, letter = (letter + 1) % 3, selector >>= 1) |
paul@181 | 36 | s[i] = permissions & selector ? letters[letter] : '-'; |
paul@181 | 37 | |
paul@181 | 38 | return s; |
paul@181 | 39 | } |