libexplain
1.4.D001
|
00001 /* 00002 * libexplain - Explain errno values returned by libc functions 00003 * Copyright (C) 2008, 2009, 2011, 2013 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_PUTC_H 00020 #define LIBEXPLAIN_PUTC_H 00021 00027 #include <libexplain/gcc_attributes.h> 00028 #include <libexplain/gcc_attributes.h> 00029 00030 #include <stdio.h> 00031 00032 #ifdef __cplusplus 00033 extern "C" { 00034 #endif 00035 00042 void explain_putc_or_die_failed(int c, FILE *fp); 00043 00050 void explain_putc_on_error_failed(int c, FILE *fp); 00051 00072 #if __GNUC__ >= 3 00073 static __inline__ 00074 #endif 00075 void explain_putc_or_die(int c, FILE *fp) 00076 #if __GNUC__ >= 3 00077 __attribute__((always_inline)) 00078 #endif 00079 ; 00080 00081 #if __GNUC__ >= 3 00082 00083 static __inline__ void 00084 explain_putc_or_die(int c, FILE *fp) 00085 { 00086 /* 00087 * By using inline, the user doesn't have to pay a one-function- 00088 * call-per-character penalty for using libexplain, because putc is 00089 * usually a macro or an inline that only calls overflow when the 00090 * buffer is exhausted. 00091 */ 00092 if (putc(c, fp) == EOF) 00093 explain_putc_or_die_failed(c, fp); 00094 } 00095 00096 #endif 00097 00120 #if __GNUC__ >= 3 00121 static __inline__ 00122 #endif 00123 int explain_putc_on_error(int c, FILE *fp) 00124 #if __GNUC__ >= 3 00125 __attribute__((always_inline)) 00126 #endif 00127 LIBEXPLAIN_WARN_UNUSED_RESULT; 00128 00129 #if __GNUC__ >= 3 00130 00131 static __inline__ int 00132 explain_putc_on_error(int c, FILE *fp) 00133 { 00134 /* 00135 * By using inline, the user doesn't have to pay a one-function- 00136 * call-per-character penalty for using libexplain, because putc is 00137 * usually a macro or an inline that only calls overflow when the 00138 * buffer is exhausted. 00139 */ 00140 int result = putc(c, fp); 00141 if (result == EOF) 00142 explain_putc_on_error_failed(c, fp); 00143 return result; 00144 } 00145 00146 #endif 00147 00187 const char *explain_putc(int c, FILE *fp) 00188 LIBEXPLAIN_WARN_UNUSED_RESULT; 00189 00233 const char *explain_errno_putc(int errnum, int c, FILE *fp) 00234 LIBEXPLAIN_WARN_UNUSED_RESULT; 00235 00274 void explain_message_putc(char *message, int message_size, int c, FILE *fp); 00275 00318 void explain_message_errno_putc(char *message, int message_size, int errnum, 00319 int c, FILE *fp); 00320 00321 #ifdef __cplusplus 00322 } 00323 #endif 00324 00325 /* vim: set ts=8 sw=4 et : */ 00326 #endif /* LIBEXPLAIN_PUTC_H */