Handle missing O_TMPFILE gracefully and document tempfile() in README

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
Joachim Nilsson
2015-06-22 22:02:39 +02:00
parent c5434a4bc0
commit 35b43c5c56
3 changed files with 14 additions and 1 deletions
+1 -1
View File
@@ -39,7 +39,7 @@ STRIPINST := $(INSTALL) -s --strip-program=$(CROSS)strip -m 0755
CFLAGS += -fPIC
CFLAGS += -Os
CPPFLAGS += -D_GNU_SOURCE
CPPFLAGS += -W -Wall -Werror
CPPFLAGS += -W -Wall
ARFLAGS = crus
MAKEFLAGS = --no-print-directory --silent
+6
View File
@@ -74,6 +74,12 @@ Generic Functions
Very simple `rsync()` to copy files files and directories
recursively.
- `tempfile()`
Secure replacement for `tmpfile()`. Creates an invisible temporary
file in `/tmp` that is removed when the returned %FILE pointer is
closed.
OpenBSD Functions
-----------------
+7
View File
@@ -21,6 +21,11 @@
#include <stdio.h> /* fdopen() */
#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 020200000 /* Define and let it fail at runtime */
#endif
/**
* tempfile - A secure tmpfile() replacement
*
@@ -29,6 +34,8 @@
* for security. When the %FILE is fclose()'ed the file contents is
* lost. The file is hidden in the %_PATH_TMP directory on the system.
*
* This function requires Linux 3.11, or later, due to %O_TMPFILE.
*
* Returns:
* An open %FILE pointer, or %NULL on error.
*/