From 61bd12c1f9340fc786912a36dbaa491bf8ad56a0 Mon Sep 17 00:00:00 2001 From: brarcher Date: Mon, 27 Jan 2014 03:18:26 +0000 Subject: [PATCH] move common log opening code to common function git-svn-id: svn+ssh://svn.code.sf.net/p/check/code/trunk@1076 64e312b2-a51f-0410-8e61-82d0ca0eb02a --- src/check_log.c | 54 +++++++++++++++++++++++++++---------------------- 1 file changed, 30 insertions(+), 24 deletions(-) diff --git a/src/check_log.c b/src/check_log.c index c9523c7..de739be 100644 --- a/src/check_log.c +++ b/src/check_log.c @@ -409,40 +409,46 @@ void subunit_lfun (SRunner *sr, FILE *file, enum print_output printmode, } #endif -FILE *srunner_open_lfile (SRunner *sr) +static FILE * srunner_open_file(const char * filename) { - FILE *f = NULL; - if (srunner_has_log (sr)) { - f = fopen(srunner_log_fname(sr), "w"); + FILE * f = NULL; + f = fopen(filename, "w"); if (f == NULL) - eprintf ("Error in call to fopen while opening log file %s:", __FILE__, __LINE__ - 2, - sr->log_fname); - } - return f; + { + eprintf ("Error in call to fopen while opening file %s:", __FILE__, __LINE__ - 2, + filename); + } + return f; +} + +FILE *srunner_open_lfile (SRunner *sr) +{ + FILE *f = NULL; + if (srunner_has_log (sr)) + { + f = srunner_open_file(srunner_log_fname(sr)); + } + return f; } FILE *srunner_open_xmlfile (SRunner *sr) { - FILE *f = NULL; - if (srunner_has_xml (sr)) { - f = fopen(srunner_xml_fname(sr), "w"); - if (f == NULL) - eprintf ("Error in call to fopen while opening xml file %s:", __FILE__, __LINE__ - 2, - sr->xml_fname); - } - return f; + FILE *f = NULL; + if (srunner_has_xml (sr)) + { + f = srunner_open_file(srunner_xml_fname(sr)); + } + return f; } FILE *srunner_open_tapfile (SRunner *sr) { - FILE *f = NULL; - if (srunner_has_tap (sr)) { - f = fopen(srunner_tap_fname(sr), "w"); - if (f == NULL) - eprintf ("Error in call to fopen while opening tap file %s:", __FILE__, __LINE__ - 2, - sr->tap_fname); - } - return f; + FILE *f = NULL; + if (srunner_has_tap (sr)) + { + f = srunner_open_file(srunner_tap_fname(sr)); + } + return f; } void srunner_init_logging (SRunner *sr, enum print_output print_mode) -- 2.40.0