libexplain  1.4.D001
libexplain/getc.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_GETC_H
00020 #define LIBEXPLAIN_GETC_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 (generated by the ./configure
00039  * script generated by GNU Autoconf) are not suitable for inclusion in
00040  * the client API because they have no LIBEXPLAIN_ namespace prefix.
00041  */
00042 #if __GNUC__ >= 3 || defined(__clang__)
00043 
00049 void explain_getc_or_die_failed(FILE *fp);
00050 #endif
00051 
00070 #if __GNUC__ >= 3 || defined(__clang__)
00071 static __inline__
00072 #endif
00073 int explain_getc_or_die(FILE *fp)
00074 #if __GNUC__ >= 3 || defined(__clang__)
00075 __attribute__((always_inline))
00076 #endif
00077 ;
00078 
00079 #if __GNUC__ >= 3 || defined(__clang__)
00080 
00081 static __inline__ int
00082 explain_getc_or_die(FILE *fp)
00083 {
00084     /*
00085      * By using inline, the users dosn't have to pay a one-function-
00086      * call-per-character penalty for using libexplain, because getc is
00087      * usually a macro or an inline that only calls underflow when the
00088      * buffer is exhausted.
00089      */
00090     int c = getc(fp);
00091     if (c == EOF && ferror(fp))
00092         explain_getc_or_die_failed(fp);
00093     return c;
00094 }
00095 
00096 #endif
00097 
00119 int explain_getc_on_error(FILE *fp)
00120                                                   LIBEXPLAIN_WARN_UNUSED_RESULT;
00121 
00159 const char *explain_getc(FILE *fp)
00160                                                   LIBEXPLAIN_WARN_UNUSED_RESULT;
00161 
00203 const char *explain_errno_getc(int errnum, FILE *fp)
00204                                                   LIBEXPLAIN_WARN_UNUSED_RESULT;
00205 
00242 void explain_message_getc(char *message, int message_size, FILE *fp);
00243 
00284 void explain_message_errno_getc(char *message, int message_size, int errnum,
00285     FILE *fp);
00286 
00287 #ifdef __cplusplus
00288 }
00289 #endif
00290 
00291 /* vim: set ts=8 sw=4 et : */
00292 #endif /* LIBEXPLAIN_GETC_H */