From 0043e99318bfade48c7a378997b691694b06edd0 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Tue, 3 Apr 2018 22:11:43 -0500 Subject: Factor out xtempfile() --- lib/xwrap.c | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'lib/xwrap.c') diff --git a/lib/xwrap.c b/lib/xwrap.c index 74da0ed1..562cbaf4 100644 --- a/lib/xwrap.c +++ b/lib/xwrap.c @@ -377,6 +377,16 @@ int notstdio(int fd) return fd; } +int xtempfile(char *name, char **tempname) +{ + int fd; + + *tempname = xmprintf("%s%s", name, "XXXXXX"); + if(-1 == (fd = mkstemp(*tempname))) error_exit("no temp file"); + + return fd; +} + // Create a file but don't return stdin/stdout/stderr int xcreate(char *path, int flags, int mode) { -- cgit v1.2.3