libexplain
1.4.D001
|
00001 /* 00002 * libexplain - Explain errno values returned by libc functions 00003 * Copyright (C) 2009, 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/stdio.h> 00021 00022 #include <libexplain/buffer/errno/pclose.h> 00023 #include <libexplain/buffer/wait_status.h> 00024 #include <libexplain/common_message_buffer.h> 00025 #include <libexplain/pclose.h> 00026 #include <libexplain/string_buffer.h> 00027 #include <libexplain/output.h> 00028 00029 00030 int 00031 explain_pclose_success(FILE *fp) 00032 { 00033 int status; 00034 00035 status = pclose(fp); 00036 if (status < 0) 00037 { 00038 explain_output_error("%s", explain_pclose(fp)); 00039 } 00040 else if (status != 0) 00041 { 00042 explain_string_buffer_t sb; 00043 00044 explain_string_buffer_init 00045 ( 00046 &sb, 00047 explain_common_message_buffer, 00048 explain_common_message_buffer_size 00049 ); 00050 explain_buffer_errno_pclose(&sb, 0, fp); 00051 00052 /* FIXME: i18n */ 00053 explain_string_buffer_puts(&sb, ", but "); 00054 explain_buffer_wait_status(&sb, status); 00055 explain_output_error("%s", explain_common_message_buffer); 00056 } 00057 return status; 00058 } 00059 00060 00061 void 00062 explain_pclose_success_or_die(FILE *fp) 00063 { 00064 if (explain_pclose_success(fp)) 00065 explain_output_exit_failure(); 00066 } 00067 00068 00069 /* vim: set ts=8 sw=4 et : */