- res = pread(fd, snapshot, snapshot_len, 0);
- if (res != snapshot_len)
- err(1, "Reading %zu bytes = %u", (size_t)snapshot_len, res);
- snapshot_uptodate = true;
+ return true;
+}
+
+static bool compare_file(int fd, const char *snapshot, off_t snapshot_len)
+{
+ char *contents;
+ bool same;
+
+ /* over-length read serves as length check. */
+ contents = malloc(snapshot_len+1);
+ same = pread(fd, contents, snapshot_len+1, 0) == snapshot_len
+ && is_same(snapshot, contents, snapshot_len);
+ free(contents);
+ return same;