Skip to content

Commit

Permalink
(platform) add missing tempfile.c
Browse files Browse the repository at this point in the history
This should've been added with the keymap forwarding code.
  • Loading branch information
letoram committed Jun 25, 2023
1 parent 7bec456 commit 5410803
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/platform/posix/tempfile.c
@@ -0,0 +1,30 @@
#include <stdlib.h>
#include <unistd.h>

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;
}

0 comments on commit 5410803

Please sign in to comment.