summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--util.c16
-rw-r--r--util.h1
2 files changed, 17 insertions, 0 deletions
diff --git a/util.c b/util.c
index d292bf8..4e4c0af 100644
--- a/util.c
+++ b/util.c
@@ -201,3 +201,19 @@ err_close:
fclose(f);
return -1;
}
+
+/* Returns end - start + 1, assuming start < end */
+u64 u64_range(u64 start, u64 end)
+{
+ u64 res;
+
+ res.h = end.h - start.h;
+ res.l = end.l - start.l;
+
+ if (end.l < start.l)
+ res.h--;
+ if (++res.l == 0)
+ res.h++;
+
+ return res;
+}
diff --git a/util.h b/util.h
index 894bd2f..4a72491 100644
--- a/util.h
+++ b/util.h
@@ -27,3 +27,4 @@
int checksum(const u8 *buf, size_t len);
void *mem_chunk(size_t base, size_t len, const char *devmem);
int write_dump(size_t base, size_t len, const void *data, const char *dumpfile, int add);
+u64 u64_range(u64 start, u64 end);