libexplain  1.4.D001
libexplain/putchar.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_PUTCHAR_H
00020 #define LIBEXPLAIN_PUTCHAR_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 
00050 void explain_putchar_or_die_failed(int c);
00051 
00058 void explain_putchar_on_error_failed(int c);
00059 
00060 #endif
00061 
00081 #if __GNUC__ >= 3 || defined(__clang__)
00082 static __inline__
00083 #endif
00084 void explain_putchar_or_die(int c)
00085 #if __GNUC__ >= 3 || defined(__clang__)
00086 __attribute__((always_inline))
00087 #endif
00088     ;
00089 
00090 #if __GNUC__ >= 3 || defined(__clang__)
00091 
00092 static __inline__ void
00093 explain_putchar_or_die(int c)
00094 {
00095     /*
00096      * By using inline, the user doesn't have to pay a one-function-
00097      * call-per-character penalty for using libexplain, because putchar
00098      * is usually a macro or an inline that only calls overflow when
00099      * the buffer is exhausted.
00100      */
00101     if (putchar(c) == EOF)
00102         explain_putchar_or_die_failed(c);
00103 }
00104 
00105 #endif
00106 
00128 #if __GNUC__ >= 3 || defined(__clang__)
00129 static __inline__
00130 #endif
00131 int explain_putchar_on_error(int c)
00132 #if __GNUC__ >= 3 || defined(__clang__)
00133 __attribute__((always_inline))
00134 #endif
00135                                                   LIBEXPLAIN_WARN_UNUSED_RESULT;
00136 
00137 #if __GNUC__ >= 3 || defined(__clang__)
00138 
00139 static __inline__ int
00140 explain_putchar_on_error(int c)
00141 {
00142     /*
00143      * By using inline, the user doesn't have to pay a one-function-
00144      * call-per-character penalty for using libexplain, because putchar
00145      * is usually a macro or an inline that only calls overflow when
00146      * the buffer is exhausted.
00147      */
00148     int result = putchar(c);
00149     if (result == EOF)
00150         explain_putchar_on_error_failed(c);
00151     return result;
00152 }
00153 
00154 #endif
00155 
00193 const char *explain_putchar(int c)
00194                                                   LIBEXPLAIN_WARN_UNUSED_RESULT;
00195 
00237 const char *explain_errno_putchar(int errnum, int c)
00238                                                   LIBEXPLAIN_WARN_UNUSED_RESULT;
00239 
00275 void explain_message_putchar(char *message, int message_size, int c);
00276 
00316 void explain_message_errno_putchar(char *message, int message_size, int errnum,
00317     int c);
00318 
00319 #ifdef __cplusplus
00320 }
00321 #endif
00322 
00323 /* vim: set ts=8 sw=4 et : */
00324 #endif /* LIBEXPLAIN_PUTCHAR_H */