X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=src%2Frrd_first.c;h=3782d4ab9c35f7ba9bc042a90a192cf3949e8552;hb=818549a636c390fb4a8390a7e2195a52293cd56b;hp=f4e8d4063f2db5709f4116cefb45a1fb3fdd2dbd;hpb=02ef386b0946ceb31dcedfd88393a0dd5e0e266d;p=rrdtool.git diff --git a/src/rrd_first.c b/src/rrd_first.c index f4e8d40..3782d4a 100644 --- a/src/rrd_first.c +++ b/src/rrd_first.c @@ -55,13 +55,14 @@ rrd_first(int argc, char **argv) time_t rrd_first_r(const char *filename, const int rraindex) { - long rra_start, + off_t rra_start, timer; time_t then; - FILE *in_file; rrd_t rrd; + rrd_file_t *rrd_file; - if(rrd_open(filename,&in_file,&rrd, RRD_READONLY)==-1){ + rrd_file = rrd_open(filename,&rrd, RRD_READONLY); + if (rrd_file == NULL) { rrd_set_error("could not open RRD"); return(-1); } @@ -69,12 +70,12 @@ rrd_first_r(const char *filename, const int rraindex) if((rraindex < 0) || (rraindex >= (int)rrd.stat_head->rra_cnt)) { rrd_set_error("invalid rraindex number"); rrd_free(&rrd); - fclose(in_file); + close(rrd_file->fd); return(-1); } - rra_start = ftell(in_file); - fseek(in_file, + rra_start = rrd_file->header_len; + rrd_seek(rrd_file, (rra_start + (rrd.rra_ptr[rraindex].cur_row+1) * rrd.stat_head->ds_cnt * @@ -82,7 +83,7 @@ rrd_first_r(const char *filename, const int rraindex) SEEK_SET); timer = - (rrd.rra_def[rraindex].row_cnt-1); if (rrd.rra_ptr[rraindex].cur_row + 1 > rrd.rra_def[rraindex].row_cnt) { - fseek(in_file,rra_start,SEEK_SET); + rrd_seek(rrd_file,rra_start,SEEK_SET); } then = (rrd.live_head->last_up - rrd.live_head->last_up % @@ -91,10 +92,8 @@ rrd_first_r(const char *filename, const int rraindex) rrd.rra_def[rraindex].pdp_cnt*rrd.stat_head->pdp_step); rrd_free(&rrd); - fclose(in_file); + close(rrd_file->fd); + rrd_close(rrd_file); return(then); } - - -