diff options
author | Shannon Booth <shannon.ml.booth@gmail.com> | 2019-12-26 16:46:33 +1300 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-12-26 10:05:59 +0100 |
commit | bbf878e9876c1b427e309d5f80d8fb7be297b0a8 (patch) | |
tree | 735603f074f4a8e9ea366216b6392a2fb8fe7a0c /Libraries/LibC/stdio.cpp | |
parent | f6bd4f86919de178c3e3d74dd7a08b7e32942410 (diff) | |
download | serenity-bbf878e9876c1b427e309d5f80d8fb7be297b0a8.zip |
LibC: Implement tmpfile()
Diffstat (limited to 'Libraries/LibC/stdio.cpp')
-rw-r--r-- | Libraries/LibC/stdio.cpp | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/Libraries/LibC/stdio.cpp b/Libraries/LibC/stdio.cpp index ff5d277a70..574b770e70 100644 --- a/Libraries/LibC/stdio.cpp +++ b/Libraries/LibC/stdio.cpp @@ -635,7 +635,17 @@ void funlockfile(FILE* filehandle) FILE* tmpfile() { - dbgprintf("FIXME: Implement tmpfile()\n"); - ASSERT_NOT_REACHED(); + char tmp_path[] = "/tmp/XXXXXX"; + if (!__generate_unique_filename(tmp_path)) + return nullptr; + + int fd = open(tmp_path, O_CREAT | O_EXCL | O_RDWR, S_IWUSR | S_IRUSR); + if (fd < 0) + return nullptr; + + // FIXME: instead of using this hack, implement with O_TMPFILE or similar + unlink(tmp_path); + + return make_FILE(fd); } } |