summaryrefslogtreecommitdiff
path: root/util.c
diff options
context:
space:
mode:
authorkhali <khali>2008-02-16 18:12:35 +0000
committerkhali <khali>2008-02-16 18:12:35 +0000
commit8a1d29dcc8b4dff78b2d5d177f95e65350e69458 (patch)
treebbc22a0b6ef4dd7315490a785cdaf0d1f5fc4c29 /util.c
parent4ae267cce98c4d4715d06d87c8f1b7d9a4e1e675 (diff)
downloaddmidecode-8a1d29dcc8b4dff78b2d5d177f95e65350e69458.tar.gz
New option --dump-bin, dump the DMI data to a sparse binary file.
Diffstat (limited to 'util.c')
-rw-r--r--util.c42
1 files changed, 42 insertions, 0 deletions
diff --git a/util.c b/util.c
index 9eda714..9266b67 100644
--- a/util.c
+++ b/util.c
@@ -163,3 +163,45 @@ void *mem_chunk(size_t base, size_t len, const char *devmem)
return p;
}
+
+int write_dump(size_t base, size_t len, const void *data, const char *dumpfile)
+{
+ FILE *f;
+
+ f=fopen(dumpfile, "r+b");
+ if(!f && errno==ENOENT)
+ f=fopen(dumpfile, "wb");
+ if(!f)
+ {
+ fprintf(stderr, "%s: ", dumpfile);
+ perror("fopen");
+ return -1;
+ }
+
+ if(fseek(f, base, SEEK_SET)!=0)
+ {
+ fprintf(stderr, "%s: ", dumpfile);
+ perror("fseek");
+ goto err_close;
+ }
+
+ if(fwrite(data, len, 1, f)!=1)
+ {
+ fprintf(stderr, "%s: ", dumpfile);
+ perror("fwrite");
+ goto err_close;
+ }
+
+ if(fclose(f))
+ {
+ fprintf(stderr, "%s: ", dumpfile);
+ perror("fclose");
+ return -1;
+ }
+
+ return 0;
+
+err_close:
+ fclose(f);
+ return -1;
+}