From: Richard Kettlewell Date: Wed, 15 Jun 2011 21:44:50 +0000 (+0100) Subject: MacOS support. X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=5f6430e49fe572cae4897f53275d52d2df4da58d;p=vbig.git MacOS support. Uses purge to implement --flush. --- diff --git a/configure.ac b/configure.ac index 58f96cb..01285c3 100644 --- a/configure.ac +++ b/configure.ac @@ -5,6 +5,16 @@ AM_INIT_AUTOMAKE([1.10]) m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES]) AC_CONFIG_SRCDIR([vbig.cc]) AM_CONFIG_HEADER([config.h]) +AC_CANONICAL_HOST +case "$host" in +*-*-darwin* ) + AC_DEFINE([PURGE_COMMAND],["purge"], [Command to purge filesystem cache]) + ;; +*-*-linux* ) + AC_DEFINE([DROP_CACHE_FILE],["/proc/sys/vm/drop_caches"], + [Path to filesystem cache purge interface]) + ;; +esac AC_LANG([C++]) AC_PROG_CXX AC_PROG_RANLIB diff --git a/vbig.1 b/vbig.1 index 11cd637..1c8216f 100644 --- a/vbig.1 +++ b/vbig.1 @@ -32,7 +32,7 @@ by the equivalent \fB--create\fR call. .TP .B --flush\fR, \fB-f Flush cached data after creating the file or before verifying it. -Only root can use this option. +On some platforms, only root can use this option. .TP .B --help\fR, \fB-h Displays a usage message. diff --git a/vbig.cc b/vbig.cc index cc81de9..54f3ea1 100644 --- a/vbig.cc +++ b/vbig.cc @@ -9,9 +9,6 @@ #include #include "Arcfour.h" -// Path to magic file to drop filesystem caches -static const char dropCaches[] = "/proc/sys/vm/drop_caches"; - // Command line options const struct option opts[] = { { "seed", required_argument, 0, 's' }, @@ -65,12 +62,27 @@ static void flushCache(FILE *fp) { // synced. if(fsync(fileno(fp)) < 0) fatal(errno, "fsync"); +#if defined DROP_CACHE_FILE int fd; - if((fd = open(dropCaches, O_WRONLY, 0)) < 0) - fatal(errno, "%s", dropCaches); + if((fd = open(DROP_CACHE_FILE, O_WRONLY, 0)) < 0) + fatal(errno, "%s", DROP_CACHE_FILE); if(write(fd, "3\n", 2) < 0) - fatal(errno, "%s", dropCaches); + fatal(errno, "%s", DROP_CACHE_FILE); close(fd); +#elif defined PURGE_COMMAND + int rc; + if((rc = system(PURGE_COMMAND)) < 0) + fatal(errno, "executing %s", PURGE_COMMAND); + else if(rc) { + if(WIFSIGNALED(rc)) { + fprintf(stderr, "%s%s\n", + strsignal(WTERMSIG(rc)), + WCOREDUMP(rc) ? " (core dumped)" : ""); + exit(WTERMSIG(rc) + 128); + } else + exit(WEXITSTATUS(rc)); + } +#endif } int main(int argc, char **argv) {