libexplain  1.4.D001
libexplain/buffer/resource.c
Go to the documentation of this file.
00001 /*
00002  * libexplain - Explain errno values returned by libc functions
00003  * Copyright (C) 2008, 2009, 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/resource.h>
00020 
00021 #include <libexplain/buffer/resource.h>
00022 #include <libexplain/parse_bits.h>
00023 #include <libexplain/sizeof.h>
00024 
00025 
00026 static const explain_parse_bits_table_t table[] =
00027 {
00028 #ifdef RLIMIT_CPU
00029     { "RLIMIT_CPU", RLIMIT_CPU },
00030 #endif
00031 #ifdef RLIMIT_FSIZE
00032     { "RLIMIT_FSIZE", RLIMIT_FSIZE },
00033 #endif
00034 #ifdef RLIMIT_DATA
00035     { "RLIMIT_DATA", RLIMIT_DATA },
00036 #endif
00037 #ifdef RLIMIT_STACK
00038     { "RLIMIT_STACK", RLIMIT_STACK },
00039 #endif
00040 #ifdef RLIMIT_CORE
00041     { "RLIMIT_CORE", RLIMIT_CORE },
00042 #endif
00043 #ifdef __RLIMIT_RSS
00044     { "__RLIMIT_RSS", __RLIMIT_RSS },
00045 #endif
00046 #ifdef RLIMIT_RSS
00047     { "RLIMIT_RSS", RLIMIT_RSS },
00048 #endif
00049 #ifdef __RLIMIT_NPROC
00050     { "__RLIMIT_NPROC", __RLIMIT_NPROC },
00051 #endif
00052 #ifdef RLIMIT_NPROC
00053     { "RLIMIT_NPROC", RLIMIT_NPROC },
00054 #endif
00055 #ifdef RLIMIT_NOFILE
00056     { "RLIMIT_NOFILE", RLIMIT_NOFILE },
00057 #endif
00058 #ifdef RLIMIT_OFILE
00059     { "RLIMIT_OFILE", RLIMIT_OFILE },
00060 #endif
00061 #ifdef __RLIMIT_MEMLOCK
00062     { "__RLIMIT_MEMLOCK", __RLIMIT_MEMLOCK },
00063 #endif
00064 #ifdef RLIMIT_MEMLOCK
00065     { "RLIMIT_MEMLOCK", RLIMIT_MEMLOCK },
00066 #endif
00067 #ifdef RLIMIT_AS
00068     { "RLIMIT_AS", RLIMIT_AS },
00069 #endif
00070 #ifdef __RLIMIT_LOCKS
00071     { "__RLIMIT_LOCKS", __RLIMIT_LOCKS },
00072 #endif
00073 #ifdef RLIMIT_LOCKS
00074     { "RLIMIT_LOCKS", RLIMIT_LOCKS },
00075 #endif
00076 #ifdef __RLIMIT_SIGPENDING
00077     { "__RLIMIT_SIGPENDING", __RLIMIT_SIGPENDING },
00078 #endif
00079 #ifdef RLIMIT_SIGPENDING
00080     { "RLIMIT_SIGPENDING", RLIMIT_SIGPENDING },
00081 #endif
00082 #ifdef __RLIMIT_MSGQUEUE
00083     { "__RLIMIT_MSGQUEUE", __RLIMIT_MSGQUEUE },
00084 #endif
00085 #ifdef RLIMIT_MSGQUEUE
00086     { "RLIMIT_MSGQUEUE", RLIMIT_MSGQUEUE },
00087 #endif
00088 #ifdef __RLIMIT_NICE
00089     { "__RLIMIT_NICE", __RLIMIT_NICE },
00090 #endif
00091 #ifdef RLIMIT_NICE
00092     { "RLIMIT_NICE", RLIMIT_NICE },
00093 #endif
00094 #ifdef __RLIMIT_RTPRIO
00095     { "__RLIMIT_RTPRIO", __RLIMIT_RTPRIO },
00096 #endif
00097 #ifdef RLIMIT_RTPRIO
00098     { "RLIMIT_RTPRIO", RLIMIT_RTPRIO },
00099 #endif
00100 #ifdef __RLIMIT_NLIMITS
00101     { "__RLIMIT_NLIMITS", __RLIMIT_NLIMITS },
00102 #endif
00103 #ifdef __RLIM_NLIMITS
00104     { "__RLIM_NLIMITS", __RLIM_NLIMITS },
00105 #endif
00106 #ifdef RLIMIT_NLIMITS
00107     { "RLIMIT_NLIMITS", RLIMIT_NLIMITS },
00108 #endif
00109 #ifdef RLIM_NLIMITS
00110     { "RLIM_NLIMITS", RLIM_NLIMITS },
00111 #endif
00112 };
00113 
00114 
00115 void
00116 explain_buffer_resource(explain_string_buffer_t *sb, int resource)
00117 {
00118     const explain_parse_bits_table_t *tp;
00119 
00120     tp = explain_parse_bits_find_by_value(resource, table, SIZEOF(table));
00121     if (tp)
00122         explain_string_buffer_puts(sb, tp->name);
00123     else
00124         explain_string_buffer_printf(sb, "%d", resource);
00125 }
00126 
00127 
00128 int
00129 explain_parse_resource_or_die(const char *text, const char *caption)
00130 {
00131     return explain_parse_bits_or_die(text, table, SIZEOF(table), caption);
00132 }
00133 
00134 
00135 /* vim: set ts=8 sw=4 et : */