Skip to content

Instantly share code, notes, and snippets.

@shulima
Created March 25, 2015 22:23
Show Gist options
  • Save shulima/c45bc24af8e0291bfb95 to your computer and use it in GitHub Desktop.
Save shulima/c45bc24af8e0291bfb95 to your computer and use it in GitHub Desktop.
Check if POSIX_FADVISE exists before using it
diff --git a/builder/pxzcat-c.c b/builder/pxzcat-c.c
index 42610c0..17886d6 100644
--- a/builder/pxzcat-c.c
+++ b/builder/pxzcat-c.c
@@ -208,8 +208,10 @@ pxzcat (value filenamev, value outputfilev, unsigned nr_threads)
unix_error (err, "ftruncate", outputfilev);
}
+#if defined HAVE_POSIX_FADVISE
/* Tell the kernel we won't read the output file. */
ignore_value (posix_fadvise (fd, 0, 0, POSIX_FADV_RANDOM|POSIX_FADV_DONTNEED));
+#endif
/* Iterate over blocks. */
iter_blocks (idx, nr_threads, filenamev, fd, outputfilev, ofd);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment