libexplain  1.4.D001
libexplain/output/stderr.c
Go to the documentation of this file.
00001 /*
00002  * libexplain - Explain errno values returned by libc functions
00003  * Copyright (C) 2010, 2012, 2013 Peter Miller
00004  * Written by Peter Miller <pmiller@opensource.org.au>
00005  *
00006  * This program is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU Lesser General Public License as
00008  * published by the Free Software Foundation; either version 3 of the
00009  * License, or (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public License
00017  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00018  */
00019 
00020 #include <libexplain/ac/stdlib.h>
00021 
00022 #include <libexplain/output/stderr.h>
00023 #include <libexplain/wrap_and_print.h>
00024 
00025 
00026 static void
00027 message(explain_output_t *op, const char *text)
00028 {
00029     /*
00030      * If stderr and stdout are writing to the same terminal (etc) the
00031      * buffered nature of stdout means that the error may appear in
00032      * advance of the output.  This can be confusing for the user.  We
00033      * flush the standard output to bring the two into sync.
00034      */
00035     fflush(stdout);
00036 
00037     (void)op;
00038     explain_wrap_and_print(stderr, text);
00039 }
00040 
00041 
00042 static const explain_output_vtable_t vtable =
00043 {
00044     0, /* destructor */
00045     message,
00046     0, /* exit */
00047     sizeof(explain_output_t)
00048 };
00049 
00050 
00051 explain_output_t explain_output_static_stderr = { &vtable, 0 };
00052 
00053 
00054 explain_output_t *
00055 explain_output_stderr_new(void)
00056 {
00057     return explain_output_new(&vtable);
00058 }
00059 
00060 
00061 /* vim: set ts=8 sw=4 et : */