+// Report an error and exit
+static void fatal(int errno_value, const char *fmt, ...) {
+ va_list ap;
+ fprintf(stderr, "ERROR: ");
+ va_start(ap, fmt);
+ vfprintf(stderr, fmt, ap);
+ va_end(ap);
+ if(errno_value)
+ fprintf(stderr, ": %s", strerror(errno_value));
+ fputc('\n', stderr);
+ exit(1);
+}
+
+// Evict whatever FP points to from RAM
+static void flushCache(FILE *fp) {
+ // drop_caches only evicts clean pages, so first the target file is
+ // synced.
+ if(fsync(fileno(fp)) < 0)
+ fatal(errno, "fsync");
+ int fd;
+ if((fd = open(dropCaches, O_WRONLY, 0)) < 0)
+ fatal(errno, "%s", dropCaches);
+ if(write(fd, "3\n", 2) < 0)
+ fatal(errno, "%s", dropCaches);
+ close(fd);
+}
+