From: Peter Stamfest Date: Mon, 24 Feb 2014 19:08:40 +0000 (+0100) Subject: provide new write_fh function X-Git-Tag: v1.5.0-rc1~132^2~1^2~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a3d193b66f118754bcf332f6d6dbffa8448f3cb0;p=thirdparty%2Frrdtool-1.x.git provide new write_fh function --- 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