libexplain  1.4.D001
libexplain/buffer/lseek_whence.c
Go to the documentation of this file.
00001 /*
00002  * libexplain - Explain errno values returned by libc functions
00003  * Copyright (C) 2008-2010, 2013 Peter Miller
00004  * Written by Peter Miller <pmiller@opensource.org.au>
00005  *
00006  * This program is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU Lesser General Public License as published by
00008  * the Free Software Foundation; either version 3 of the License, or (at
00009  * 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 GNU
00014  * Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public License
00017  * along with this program. If not, see <http://www.gnu.org/licenses/>.
00018  */
00019 
00020 #include <libexplain/ac/unistd.h>
00021 
00022 #include <libexplain/buffer/lseek_whence.h>
00023 #include <libexplain/parse_bits.h>
00024 #include <libexplain/sizeof.h>
00025 #include <libexplain/string_buffer.h>
00026 
00027 static const explain_parse_bits_table_t table[] =
00028 {
00029     { "SEEK_SET", SEEK_SET },
00030     { "SEEK_CUR", SEEK_CUR },
00031     { "SEEK_END", SEEK_END },
00032 #ifdef SEEK_DATA
00033     { "SEEK_DATA", SEEK_DATA },
00034 #endif
00035 #ifdef SEEK_HOLE
00036     { "SEEK_HOLE", SEEK_HOLE },
00037 #endif
00038 #ifdef SEEK_MAX
00039     { "SEEK_MAX", SEEK_MAX },
00040 #endif
00041     { "L_SET", SEEK_SET },
00042     { "L_INCR", SEEK_CUR },
00043     { "L_XTND", SEEK_END },
00044 };
00045 
00046 
00047 void
00048 explain_buffer_lseek_whence(explain_string_buffer_t *sb, int whence)
00049 {
00050     const explain_parse_bits_table_t *tp;
00051 
00052     tp = explain_parse_bits_find_by_value(whence, table, SIZEOF(table));
00053     if (tp)
00054         explain_string_buffer_puts(sb, tp->name);
00055     else
00056         explain_string_buffer_printf(sb, "%d", whence);
00057 }
00058 
00059 
00060 int
00061 explain_lseek_whence_parse_or_die(const char *text, const char *caption)
00062 {
00063     return explain_parse_bits_or_die(text, table, SIZEOF(table), caption);
00064 }
00065 
00066 
00067 /* vim: set ts=8 sw=4 et : */