diff options
author | Tobias Klauser <tklauser@distanz.ch> | 2016-04-26 10:17:32 +0200 |
---|---|---|
committer | Tobias Klauser <tklauser@distanz.ch> | 2016-04-26 11:21:05 +0200 |
commit | f3057cdf8518d4931a12beb3f4322638500efec8 (patch) | |
tree | 8cdb4da799e34313b3c56ee9b64afc0b73aa6151 /ioops.c | |
parent | 77d5cae4d45d1def8f41d4e89b705d2953858643 (diff) |
ioops: Add mkostemp_or_die() wrapper for mkostemp(3)
Add a panic()ing wrapper for mkostemp(3). This will be used to safely
create unique temporary files.
Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
Diffstat (limited to 'ioops.c')
-rw-r--r-- | ioops.c | 10 |
1 files changed, 10 insertions, 0 deletions
@@ -1,6 +1,7 @@ #ifndef _GNU_SOURCE # define _GNU_SOURCE #endif +#include <stdlib.h> #include <unistd.h> #include <sys/types.h> #include <sys/stat.h> @@ -53,6 +54,15 @@ void create_or_die(const char *file, mode_t mode) close(fd); } +int mkostemp_or_die(char *templ, int flags) +{ + /* mode is 0600 (S_IRUSR | S_IWUSR) by default */ + int fd = mkostemp(templ, flags); + if (unlikely(fd < 0)) + panic("Cannot create unique temporary file! %s\n", strerror(errno)); + return fd; +} + void pipe_or_die(int pipefd[2], int flags) { int ret = pipe2(pipefd, flags); |