libexplain  1.4.D001
libexplain/output/warning.c
Go to the documentation of this file.
00001 /*
00002  * libexplain - a library of system-call-specific strerror replacements
00003  * Copyright (C) 2010-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/limits.h> /* for PATH_MAX on Solaris */
00021 #include <libexplain/ac/stdarg.h>
00022 #include <libexplain/ac/stdio.h>
00023 #include <libexplain/ac/sys/param.h> /* for PATH_MAX except Solaris */
00024 
00025 #include <libexplain/buffer/gettext.h>
00026 #include <libexplain/option.h>
00027 #include <libexplain/output.h>
00028 #include <libexplain/program_name.h>
00029 #include <libexplain/string_buffer.h>
00030 
00031 
00032 void
00033 explain_output_warning(const char *format, ...)
00034 {
00035     va_list         ap;
00036     explain_string_buffer_t sb;
00037 
00038     /*
00039      * Note: we can't use explain_common_message_buffer, just in case
00040      * one of the format argumnets *is* explain_common_message_buffer.
00041      * And for the same reason, we need to be about the same size.
00042      */
00043     char buf[PATH_MAX * 2 + 200];
00044 
00045     explain_string_buffer_init(&sb, buf, sizeof(buf));
00046     if (explain_option_assemble_program_name())
00047     {
00048         const char      *prog;
00049 
00050         prog = explain_program_name_get();
00051         if (prog && *prog)
00052         {
00053             explain_string_buffer_puts(&sb, prog);
00054             explain_string_buffer_puts(&sb, ": ");
00055         }
00056     }
00057 
00058     explain_buffer_gettext
00059     (
00060         &sb,
00061         i18n
00062         (
00063             /*
00064              * xgettext: this text is added to the beginning of warning
00065              * messages, to indicate they are a warning and not an error.
00066              */
00067             "warning: "
00068         )
00069     );
00070 
00071     va_start(ap, format);
00072     explain_string_buffer_vprintf(&sb, format, ap);
00073     va_end(ap);
00074 
00075     explain_output_message(buf);
00076 }
00077 
00078 
00079 /* vim: set ts=8 sw=4 et : */