return retval;
}
+static void writeData(FILE *f, const void *data, size_t len)
+{
+ size_t written = fwrite(data, len, 1, f);
+ if (written != len)
+ LOG_ERROR("failed to write %u bytes: %s", len, strerror(errno));
+}
+
static void writeLong(FILE *f, int l)
{
int i;
for (i=0; i<4; i++)
{
char c=(l>>(i*8))&0xff;
- fwrite(&c, 1, 1, f);
+ writeData(f, &c, 1);
}
}
static void writeString(FILE *f, char *s)
{
- fwrite(s, 1, strlen(s), f);
+ writeData(f, s, strlen(s));
}
/* Dump a gmon.out histogram file. */
FILE *f=fopen(filename, "w");
if (f==NULL)
return;
- fwrite("gmon", 1, 4, f);
+ writeString(f, "gmon");
writeLong(f, 0x00000001); /* Version */
writeLong(f, 0); /* padding */
writeLong(f, 0); /* padding */
writeLong(f, 0); /* padding */
- fwrite("", 1, 1, f); /* GMON_TAG_TIME_HIST */
+ u8 zero = 0; /* GMON_TAG_TIME_HIST */
+ writeData(f, &zero, 1);
/* figure out bucket size */
u32 min=samples[0];
writeLong(f, 64000000); /* 64MHz */
writeString(f, "seconds");
for (i=0; i<(15-strlen("seconds")); i++)
- {
- fwrite("", 1, 1, f); /* padding */
- }
+ writeData(f, &zero, 1);
writeString(f, "s");
/*append binary memory gmon.out profile_hist_data (profile_hist_data + profile_hist_hdr.hist_size) */
data[i*2+1]=(val>>8)&0xff;
}
free(buckets);
- fwrite(data, 1, length*2, f);
+ writeData(f, data, length * 2);
free(data);
} else
{