New special value COUNT which allows calculations based on the position of a
[rrdtool.git] / src / rrd_restore.c
index ccac072..150f1ee 100644 (file)
@@ -405,7 +405,7 @@ rrd_write(char *file_name, rrd_t *rrd)
     FILE             *rrd_file=NULL;
 
     if (strcmp("-",file_name)==0){
-      *rrd_file= *stdout;
+      rrd_file= stdout;
     } else {
       int fd = open(file_name,O_RDWR|O_CREAT|O_EXCL,0666);
       if (fd == -1 || (rrd_file = fdopen(fd,"wb")) == NULL) {
@@ -423,8 +423,12 @@ rrd_write(char *file_name, rrd_t *rrd)
 
     fwrite(rrd->rra_def,
           sizeof(rra_def_t), rrd->stat_head->rra_cnt, rrd_file);
-    
-    fwrite(rrd->live_head, sizeof(live_head_t),1, rrd_file);
+
+        /* maybe the xml hold an old formatted rrd */
+    if (atoi(rrd->stat_head->version) < 3)
+      fwrite(&(rrd->live_head->last_up), sizeof(long),1, rrd_file);
+    else
+      fwrite(rrd->live_head, sizeof(live_head_t),1, rrd_file);
 
     fwrite( rrd->pdp_prep, sizeof(pdp_prep_t),rrd->stat_head->ds_cnt,rrd_file);