tempfile(): Handle kernels older than 3.11 by wrapping tmpfile()

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
Joachim Nilsson committed 2015-08-23 02:17:45 +02:00
1 parent 8978cb9bff
commit 407e954f02
1 file changed
+6
+6
View File
@@ -17,6 +17,7 @@
#include <paths.h> #include <paths.h>
#include <fcntl.h> /* O_TMPFILE requires -D_GNU_SOURCE */ #include <fcntl.h> /* O_TMPFILE requires -D_GNU_SOURCE */
#include <linux/version.h>
#include <stdlib.h> /* mkstemp() */ #include <stdlib.h> /* mkstemp() */
#include <stdio.h> /* fdopen() */ #include <stdio.h> /* fdopen() */
#include <sys/stat.h> /* umask() */ #include <sys/stat.h> /* umask() */
@@ -41,6 +42,7 @@
*/ */
FILE *tempfile(void) FILE *tempfile(void)
{ {
#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,11,0)
int fd; int fd;
mode_t oldmask; mode_t oldmask;
@@ -51,6 +53,10 @@ FILE *tempfile(void)
return NULL; return NULL;
return fdopen(fd, "rw"); return fdopen(fd, "rw");
#else
#warning Too old kernel, reverting to wrap unsafe tmpfile() ...
return tmpfile();
#endif
} }
#ifdef UNITTEST #ifdef UNITTEST