mirror of
https://github.com/troglobit/libite.git
synced 2026-10-30 12:40:38 +00:00
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 <abs@absd.org> Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
1 parent
613d397161
commit
f3f6947604
1 file changed
+2
-11
+2
-11
@@ -17,17 +17,9 @@
|
|||||||
|
|
||||||
#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 <stdio.h> /* fdopen() */
|
#include <stdio.h> /* fdopen() */
|
||||||
#include <sys/stat.h> /* umask() */
|
#include <sys/stat.h> /* 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
|
* tempfile - A secure tmpfile() replacement
|
||||||
*
|
*
|
||||||
@@ -43,7 +35,7 @@
|
|||||||
*/
|
*/
|
||||||
FILE *tempfile(void)
|
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;
|
int fd;
|
||||||
mode_t oldmask;
|
mode_t oldmask;
|
||||||
|
|
||||||
@@ -55,8 +47,7 @@ FILE *tempfile(void)
|
|||||||
|
|
||||||
return fdopen(fd, "rw");
|
return fdopen(fd, "rw");
|
||||||
#else
|
#else
|
||||||
#warning Too old kernel, reverting to wrap unsafe tmpfile() ...
|
return tmpfile(); /* Fallback on older GLIBC/Linux and actual UNIX systems */
|
||||||
return tmpfile();
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user