diff options
| author | Klaatu <[email protected]> | 2015-05-17 15:33:21 +1200 |
|---|---|---|
| committer | Klaatu <[email protected]> | 2015-05-17 15:33:21 +1200 |
| commit | b0de699679e8f1e39af847ed172d1ba605b4370c (patch) | |
| tree | 01dac00471d61f727394e508c613b29cff0ceae5 /lib/open_tmpfd.c | |
bulk upload of source
Diffstat (limited to 'lib/open_tmpfd.c')
| -rw-r--r-- | lib/open_tmpfd.c | 18 |
1 files changed, 18 insertions, 0 deletions
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 <unistd.h> +#include <fcntl.h> +#include <errno.h> +#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; +} |
