From 54108034b120bcbe3fddb6591a9b16eee04f5791 Mon Sep 17 00:00:00 2001 From: bjornstahl Date: Sun, 25 Jun 2023 14:53:07 +0200 Subject: [PATCH] (platform) add missing tempfile.c This should've been added with the keymap forwarding code. --- src/platform/posix/tempfile.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 src/platform/posix/tempfile.c diff --git a/src/platform/posix/tempfile.c b/src/platform/posix/tempfile.c new file mode 100644 index 000000000..aa84e9ee1 --- /dev/null +++ b/src/platform/posix/tempfile.c @@ -0,0 +1,30 @@ +#include +#include + +int arcan_strbuf_tempfile(const char* msg, size_t msg_sz, const char** err) +{ + char filename[] = "arcantemp-XXXXXX"; + int state_fd; + if (-1 == (state_fd = mkstemp(filename))){ + *err = "temp file creation failed"; + return -1; + } + unlink(filename); + + size_t ntw = msg_sz; + size_t pos = 0; + while (ntw){ + ssize_t nw = write(state_fd, &msg[pos], ntw); + if (-1 == nw){ + continue; + *err = "failed to write"; + close(state_fd); + return -1; + } + ntw -= nw; + pos += nw; + } + + lseek(state_fd, SEEK_SET, 0); + return state_fd; +}