From b0de699679e8f1e39af847ed172d1ba605b4370c Mon Sep 17 00:00:00 2001 From: Klaatu Date: Sun, 17 May 2015 15:33:21 +1200 Subject: bulk upload of source --- lib/open_tmpfd.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 lib/open_tmpfd.c (limited to 'lib/open_tmpfd.c') diff --git a/lib/open_tmpfd.c b/lib/open_tmpfd.c new file mode 100644 index 0000000..e94bf32 --- /dev/null +++ b/lib/open_tmpfd.c @@ -0,0 +1,18 @@ +#include +#include +#include +#include "../ninitfeatures.h" + +int open_tmpfd(char *target, char *tmp, int mode) /*EXTRACT_INCL*/ { + unsigned long len; + char *x; + int fd; + for (len=0 ;; len++) { + x = tmp + str_copy(tmp, target); + if (len) x += fmt_ulong(x,len); + x[0] = '~'; x[1] = 0; + fd = open(tmp, O_WRONLY|O_CREAT|O_EXCL, mode); + if (fd >=0 || errno != EEXIST) break; + } + return fd; +} -- cgit v1.2.3