libexplain
1.4.D001
|
00001 /* 00002 * libexplain - Explain errno values returned by libc functions 00003 * Copyright (C) 2010, 2011, 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/output.h> 00021 00022 00023 typedef struct explain_output_tee_t explain_output_tee_t; 00024 struct explain_output_tee_t 00025 { 00026 explain_output_t inherited; 00027 explain_output_t *first; 00028 explain_output_t *second; 00029 }; 00030 00031 00032 static void 00033 tee_destructor(explain_output_t *op) 00034 { 00035 explain_output_tee_t *p; 00036 00037 p = (explain_output_tee_t *)op; 00038 explain_output_method_destructor(p->first); 00039 explain_output_method_destructor(p->second); 00040 } 00041 00042 00043 static void 00044 tee_message(explain_output_t *op, const char *text) 00045 { 00046 explain_output_tee_t *p; 00047 00048 p = (explain_output_tee_t *)op; 00049 explain_output_method_message(p->first, text); 00050 explain_output_method_message(p->second, text); 00051 } 00052 00053 00054 static void 00055 tee_exit(explain_output_t *op, int status) 00056 { 00057 explain_output_tee_t *p; 00058 00059 p = (explain_output_tee_t *)op; 00060 if (p->first->vtable->exit) 00061 p->first->vtable->exit(p->first, status); 00062 if (p->second->vtable->exit) 00063 p->second->vtable->exit(p->second, status); 00064 } 00065 00066 00067 static const explain_output_vtable_t vtable = 00068 { 00069 tee_destructor, 00070 tee_message, 00071 tee_exit, 00072 sizeof(explain_output_tee_t) 00073 }; 00074 00075 00076 explain_output_t * 00077 explain_output_tee_new(explain_output_t *first, explain_output_t *second) 00078 { 00079 explain_output_t *result; 00080 00081 if (!first) 00082 return second; 00083 if (!second) 00084 return first; 00085 result = explain_output_new(&vtable); 00086 if (result) 00087 { 00088 explain_output_tee_t *p; 00089 00090 p = (explain_output_tee_t *)result; 00091 p->first = first; 00092 p->second = second; 00093 } 00094 return result; 00095 } 00096 00097 00098 /* vim: set ts=8 sw=4 et : */