libexplain
1.4.D001
|
00001 /* 00002 * libexplain - a library of system-call-specific strerror replacements 00003 * Copyright (C) 2011, 2013 Peter Miller 00004 * 00005 * This program is free software; you can redistribute it and/or modify 00006 * it under the terms of the GNU Lesser General Public License as 00007 * published by the Free Software Foundation; either version 3 of the 00008 * License, or (at your option) any later version. 00009 * 00010 * This program is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 * Lesser General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU Lesser General Public License 00016 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00017 */ 00018 00019 #include <libexplain/ac/sys/shm.h> 00020 #include <libexplain/ac/sys/stat.h> 00021 00022 #include <libexplain/buffer/shmflg.h> 00023 #include <libexplain/option.h> 00024 #include <libexplain/parse_bits.h> 00025 00026 00027 void 00028 explain_buffer_shmflg(explain_string_buffer_t *sb, int value) 00029 { 00030 static const explain_parse_bits_table_t table[] = 00031 { 00032 #ifdef SHM_RDONLY 00033 { "SHM_RDONLY", SHM_RDONLY }, 00034 #endif 00035 #ifdef SHM_RND 00036 { "SHM_RND", SHM_RND }, 00037 #endif 00038 #ifdef SHM_REMAP 00039 { "SHM_REMAP", SHM_REMAP }, 00040 #endif 00041 #ifdef SHM_EXEC 00042 { "SHM_EXEC", SHM_EXEC }, 00043 #endif 00044 #ifdef S_IRUSR 00045 { "S_IRUSR", S_IRUSR }, 00046 #endif 00047 #ifdef S_IWUSR 00048 { "S_IWUSR", S_IWUSR }, 00049 #endif 00050 #ifdef S_IXUSR 00051 { "S_IXUSR", S_IXUSR }, 00052 #endif 00053 #ifdef S_IRGRP 00054 { "S_IRGRP", S_IRGRP }, 00055 #endif 00056 #ifdef S_IWGRP 00057 { "S_IWGRP", S_IWGRP }, 00058 #endif 00059 #ifdef S_IXGRP 00060 { "S_IXGRP", S_IXGRP }, 00061 #endif 00062 #ifdef S_IROTH 00063 { "S_IROTH", S_IROTH }, 00064 #endif 00065 #ifdef S_IWOTH 00066 { "S_IWOTH", S_IWOTH }, 00067 #endif 00068 #ifdef S_IXOTH 00069 { "S_IXOTH", S_IXOTH }, 00070 #endif 00071 }; 00072 00073 if (explain_option_symbolic_mode_bits()) 00074 { 00075 explain_parse_bits_print(sb, value, table, SIZEOF(table)); 00076 } 00077 else 00078 { 00079 int mode; 00080 00081 mode = value & 0777; 00082 value &= ~0777; 00083 if (value) 00084 { 00085 explain_parse_bits_print(sb, value, table, SIZEOF(table)); 00086 if (mode) 00087 explain_string_buffer_printf(sb, " | %04o", mode); 00088 } 00089 else 00090 { 00091 explain_string_buffer_printf(sb, "%04o", mode); 00092 } 00093 } 00094 } 00095 00096 00097 /* vim: set ts=8 sw=4 et : */