summaryrefslogtreecommitdiff
path: root/util.c
diff options
context:
space:
mode:
authorJean Delvare <jdelvare@suse.de>2017-04-11 11:41:43 +0200
committerJean Delvare <jdelvare@suse.de>2017-04-11 11:41:43 +0200
commit6d0486c40d1a68fa5c4c730531cbf32bfd9f76c4 (patch)
tree6a0233c81f9b77af466d7ddf140862a99b1bb0ad /util.c
parent6953b627a0f11f70662496a77b67aefa9dc40968 (diff)
downloaddmidecode-git-6d0486c40d1a68fa5c4c730531cbf32bfd9f76c4.tar.gz
util: Let callers pass an offset to read_file
When reading from a dump file, read_file would be more convenient to use than mem_chunk, but it lacks an offset parameter. Signed-off-by: Jean Delvare <jdelvare@suse.de>
Diffstat (limited to 'util.c')
-rw-r--r--util.c14
1 files changed, 11 insertions, 3 deletions
diff --git a/util.c b/util.c
index 538968f..0aafcb1 100644
--- a/util.c
+++ b/util.c
@@ -2,7 +2,7 @@
* Common "util" functions
* This file is part of the dmidecode project.
*
- * Copyright (C) 2002-2015 Jean Delvare <jdelvare@suse.de>
+ * Copyright (C) 2002-2017 Jean Delvare <jdelvare@suse.de>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -89,7 +89,7 @@ int checksum(const u8 *buf, size_t len)
}
/*
- * Reads all of file, up to max_len bytes.
+ * Reads all of file from given offset, up to max_len bytes.
* A buffer of max_len bytes is allocated by this function, and
* needs to be freed by the caller.
* This provides a similar usage model to mem_chunk()
@@ -98,7 +98,7 @@ int checksum(const u8 *buf, size_t len)
* sets max_len to the length actually read.
*
*/
-void *read_file(size_t *max_len, const char *filename)
+void *read_file(off_t base, size_t *max_len, const char *filename)
{
int fd;
size_t r2 = 0;
@@ -116,6 +116,14 @@ void *read_file(size_t *max_len, const char *filename)
return NULL;
}
+ if (lseek(fd, base, SEEK_SET) == -1)
+ {
+ fprintf(stderr, "%s: ", filename);
+ perror("lseek");
+ p = NULL;
+ goto out;
+ }
+
if ((p = malloc(*max_len)) == NULL)
{
perror("malloc");