From a3d193b66f118754bcf332f6d6dbffa8448f3cb0 Mon Sep 17 00:00:00 2001 From: Peter Stamfest Date: Mon, 24 Feb 2014 20:08:40 +0100 Subject: [PATCH] provide new write_fh function --- src/rrd_restore.c | 32 ++++++++++++++++++++++---------- src/rrd_restore.h | 5 +++++ 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/src/rrd_restore.c b/src/rrd_restore.c index 1ab92d8a..1dc3795f 100644 --- a/src/rrd_restore.c +++ b/src/rrd_restore.c @@ -1127,8 +1127,6 @@ int write_file( rrd_t *rrd) { FILE *fh; - unsigned int i; - unsigned int rra_offset; if (strcmp("-", file_name) == 0) fh = stdout; @@ -1157,6 +1155,28 @@ int write_file( return (-1); } } + + int rc = write_fh(fh, rrd); + + /* lets see if we had an error */ + if (ferror(fh)) { + rrd_set_error("a file error occurred while creating '%s'", file_name); + fclose(fh); + return (-1); + } + + fclose(fh); + + return rc; +} + +int write_fh( + FILE *fh, + rrd_t *rrd) +{ + unsigned int i; + unsigned int rra_offset; + if (atoi(rrd->stat_head->version) < 3) { /* we output 3 or higher */ strcpy(rrd->stat_head->version, "0003"); @@ -1188,14 +1208,6 @@ int write_file( } } - /* lets see if we had an error */ - if (ferror(fh)) { - rrd_set_error("a file error occurred while creating '%s'", file_name); - fclose(fh); - return (-1); - } - - fclose(fh); return (0); } /* int write_file */ diff --git a/src/rrd_restore.h b/src/rrd_restore.h index a6c52803..94d06f60 100644 --- a/src/rrd_restore.h +++ b/src/rrd_restore.h @@ -10,12 +10,17 @@ extern "C" { #ifndef _RRD_RESTORE_H #define _RRD_RESTORE_H +#include #include "rrd.h" int write_file( const char *file_name, rrd_t *rrd); +int write_fh( + FILE *fh, + rrd_t *rrd); + #endif -- 2.47.3