summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: e6271af)
raw | patch | inline | side by side (parent: e6271af)
author | oetiker <oetiker@a5681a0c-68f1-0310-ab6d-d61299d08faa> | |
Wed, 12 Nov 2003 22:13:55 +0000 (22:13 +0000) | ||
committer | oetiker <oetiker@a5681a0c-68f1-0310-ab6d-d61299d08faa> | |
Wed, 12 Nov 2003 22:13:55 +0000 (22:13 +0000) |
src/rrd_create.c | patch | blob | history |
diff --git a/src/rrd_create.c b/src/rrd_create.c
index 78f52d629636a6120b786bf7c086a9b333558de9..6573fc5a69280b9f67b526c8a24a2de025f8cd1e 100644 (file)
--- a/src/rrd_create.c
+++ b/src/rrd_create.c
{
unsigned long i,ii;
FILE *rrd_file;
- rrd_value_t unknown = DNAN ;
+ rrd_value_t *unknown;
+ int unkn_cnt;
if ((rrd_file = fopen(file_name,"wb")) == NULL ) {
rrd_set_error("creating '%s': %s",file_name, rrd_strerror(errno));
}
/* write the empty data area */
- for(i=0;
- i < rrd->stat_head->rra_cnt;
- i++)
- {
- for(ii=0;
- ii < rrd->rra_def[i].row_cnt
- * rrd->stat_head->ds_cnt;
- ii++){
- fwrite(&unknown,sizeof(rrd_value_t),1,rrd_file);
- }
+ if ((unknown = (rrd_value_t *)malloc(512 * sizeof(rrd_value_t))) == NULL) {
+ rrd_set_error("allocating unknown");
+ rrd_free(rrd);
+ fclose(rrd_file);
+ return(-1);
}
+ for (i = 0; i < 512; ++i)
+ unknown[i] = DNAN;
+
+ unkn_cnt = 0;
+ for (i = 0; i < rrd->stat_head->rra_cnt; i++)
+ unkn_cnt += rrd->stat_head->ds_cnt * rrd->rra_def[i].row_cnt;
+
+ while (unkn_cnt > 0) {
+ fwrite(unknown, sizeof(rrd_value_t), min(unkn_cnt, 512), rrd_file);
+ unkn_cnt -= 512;
+ }
+ free(unknown);
/* lets see if we had an error */
if(ferror(rrd_file)){