libexplain  1.4.D001
libexplain/buffer/shmctl_command.c
Go to the documentation of this file.
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 
00021 #include <libexplain/buffer/shmctl_command.h>
00022 #include <libexplain/output.h>
00023 #include <libexplain/parse_bits.h>
00024 
00025 
00026 static const explain_parse_bits_table_t table[] =
00027 {
00028 #ifdef IPC_STAT
00029     { "IPC_STAT", IPC_STAT },
00030 #endif
00031 #ifdef IPC_SET
00032     { "IPC_SET", IPC_SET },
00033 #endif
00034 #ifdef IPC_RMID
00035     { "IPC_RMID", IPC_RMID },
00036 #endif
00037 #ifdef IPC_INFO
00038     { "IPC_INFO", IPC_INFO },
00039 #endif
00040 #ifdef SHM_INFO
00041     { "SHM_INFO", SHM_INFO },
00042 #endif
00043 #ifdef SHM_STAT
00044     { "SHM_STAT", SHM_STAT },
00045 #endif
00046 #ifdef SHM_LOCK
00047     { "SHM_LOCK", SHM_LOCK },
00048 #endif
00049 #ifdef SHM_UNLOCK
00050     { "SHM_UNLOCK", SHM_UNLOCK },
00051 #endif
00052 };
00053 
00054 
00055 void
00056 explain_buffer_shmctl_command(explain_string_buffer_t *sb, int value)
00057 {
00058     explain_parse_bits_print_single(sb, value, table, SIZEOF(table));
00059 }
00060 
00061 
00062 int
00063 explain_parse_shmctl_command_or_die(const char *text, const char *caption)
00064 {
00065     int result = 0;
00066     if (explain_parse_bits(text, table, SIZEOF(table), &result) < 0)
00067     {
00068         char            part1[100];
00069         explain_string_buffer_t part1_sb;
00070         char            part2[1000];
00071         explain_string_buffer_t part2_sb;
00072 
00073         part1[0] = '\0';
00074         explain_string_buffer_init(&part1_sb, part1, sizeof(part1));
00075         if (caption && *caption)
00076             explain_string_buffer_puts(&part1_sb, caption);
00077         explain_string_buffer_init(&part2_sb, part2, sizeof(part2));
00078         explain_string_buffer_puts_quoted(&part2_sb, text);
00079 
00080         explain_output_error_and_die
00081         (
00082             "%s: unable to interpret %s as a shmctl(2) command: %s",
00083             part1,
00084             part2,
00085             explain_parse_bits_get_error()
00086         );
00087     }
00088     return result;
00089 }
00090 
00091 
00092 /* vim: set ts=8 sw=4 et : */