libexplain  1.4.D001
libexplain/getchar.h
Go to the documentation of this file.
00001 /*
00002  * libexplain - Explain errno values returned by libc functions
00003  * Copyright (C) 2008, 2009, 2013, 2014 Peter Miller
00004  *
00005  * This program is free software; you can redistribute it and/or modify it
00006  * under the terms of the GNU Lesser General Public License as published by
00007  * the Free Software Foundation; either version 3 of the License, or (at
00008  * 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 #ifndef LIBEXPLAIN_GETCHAR_H
00020 #define LIBEXPLAIN_GETCHAR_H
00021 
00027 #include <libexplain/gcc_attributes.h>
00028 #include <libexplain/large_file_support.h>
00029 
00030 #include <stdio.h>
00031 
00032 #ifdef __cplusplus
00033 extern "C" {
00034 #endif
00035 
00036 /*
00037  * FIXME: need a better inline-availability test,
00038  * but the defines in libexplain/config.h are not suitable for inclusion
00039  * in the client API because they have no LIBEXPLAIN_ namespace prefix.
00040  */
00041 #if __GNUC__ >= 3 || defined(__clang__)
00042 
00048 void explain_getchar_or_die_failed(void);
00049 #endif
00050 
00067 #if __GNUC__ >= 3 || defined(__clang__)
00068 static __inline__
00069 #endif
00070 int explain_getchar_or_die(void)
00071 #if __GNUC__ >= 3 || defined(__clang__)
00072 __attribute__((always_inline))
00073 #endif
00074 ;
00075 
00076 #if __GNUC__ >= 3 || defined(__clang__)
00077 
00078 static __inline__ int
00079 explain_getchar_or_die(void)
00080 {
00081     /*
00082      * By using inline, the users dosn't have to pay a one-function-
00083      * call-per-character penalty for using libexplain, because getc is
00084      * usually a macro or an inline that only calls underflow when the
00085      * buffer is exhausted.
00086      */
00087     int c = getchar();
00088     if (c == EOF && ferror(stdin))
00089         explain_getchar_or_die_failed();
00090     return c;
00091 }
00092 
00093 #endif
00094 
00114 int explain_getchar_on_error(void)
00115                                                   LIBEXPLAIN_WARN_UNUSED_RESULT;
00116 
00152 const char *explain_getchar(void)
00153                                                   LIBEXPLAIN_WARN_UNUSED_RESULT;
00154 
00194 const char *explain_errno_getchar(int errnum)
00195                                                   LIBEXPLAIN_WARN_UNUSED_RESULT;
00196 
00230 void explain_message_getchar(char *message, int message_size);
00231 
00269 void explain_message_errno_getchar(char *message, int message_size, int errnum);
00270 
00271 #ifdef __cplusplus
00272 }
00273 #endif
00274 
00275 /* vim: set ts=8 sw=4 et : */
00276 #endif /* LIBEXPLAIN_GETCHAR_H */