From f3f6947604b26f072972b4ae56cc09459b1cb8a2 Mon Sep 17 00:00:00 2001 From: David Brownlee Date: Sun, 29 May 2016 23:35:03 +0100 Subject: [PATCH] Handle old Linux/(G)LIBC and UNIX systems the same Linux systems pre Linux 3.11, and UNIX do not have the O_TMPFILE flag, so let's treat them the same, by wrapping tmpfile(). Signed-off-by: David Brownlee Signed-off-by: Joachim Nilsson --- tempfile.c | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/tempfile.c b/tempfile.c index c914d3e..ad94fab 100644 --- a/tempfile.c +++ b/tempfile.c @@ -17,17 +17,9 @@ #include #include /* O_TMPFILE requires -D_GNU_SOURCE */ -#include -#include /* mkstemp() */ #include /* fdopen() */ #include /* umask() */ -#ifndef O_TMPFILE /* Too old GLIBC or kernel */ -#warning O_TMPFILE missing on your system, tempfile() may not work! -#define __O_TMPFILE 020000000 -#define O_TMPFILE (__O_TMPFILE | O_DIRECTORY) /* Define and let it fail at runtime */ -#endif - /** * tempfile - A secure tmpfile() replacement * @@ -43,7 +35,7 @@ */ FILE *tempfile(void) { -#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,11,0) +#ifdef O_TMPFILE /* Only on Linux, with fairly recent (G)LIBC */ int fd; mode_t oldmask; @@ -55,8 +47,7 @@ FILE *tempfile(void) return fdopen(fd, "rw"); #else -#warning Too old kernel, reverting to wrap unsafe tmpfile() ... - return tmpfile(); + return tmpfile(); /* Fallback on older GLIBC/Linux and actual UNIX systems */ #endif }