[PATCH 3/4] lib/fileutils: advice there is no point caching temporary files

Sami Kerola
2013-09-08T16:09:24Z

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
lib/fileutils.c | 4 ++++
1 file changed, 4 insertions(+)

diff --git a/lib/fileutils.c b/lib/fileutils.c
index 92b474c..23cf80c 100644
--- a/lib/fileutils.c
+++ b/lib/fileutils.c
@@ -8,6 +8,7 @@
#include <unistd.h>
#include <sys/time.h>
#include <sys/resource.h>
+#include <fcntl.h>

#include "c.h"
#include "fileutils.h"
@@ -43,6 +44,9 @@ int xmkstemp(char **tmpname, char *dir)
free(localtmp);
localtmp = NULL;
}
+#ifdef POSIX_FADV_NOREUSE
+ posix_fadvise(fd, 0, lseek(fd, 0, 0), POSIX_FADV_NOREUSE);
+#endif
*tmpname = localtmp;
return fd;
}
--
1.8.4