summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibC/stdio.cpp
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2021-01-22 19:23:36 +0100
committerAndreas Kling <kling@serenityos.org>2021-01-22 19:39:44 +0100
commitb0f19c2af45718f8eb27638a1135c3cc03a92ec9 (patch)
tree0de09924a6610b4f43c4d11344a435376982ddcc /Userland/Libraries/LibC/stdio.cpp
parent2cd07c6212ab3c2607e8bd2a94f21aa82e3c5fd9 (diff)
downloadserenity-b0f19c2af45718f8eb27638a1135c3cc03a92ec9.zip
LibC: Templatize unique filename enumeration for mkstemp() et al
This allows us to implement mkstemp() with open() directly, instead of first lstat()'ing, and then open()'ing the filename. Also implement tmpfile() in terms of mkstemp() instead of mktemp().
Diffstat (limited to 'Userland/Libraries/LibC/stdio.cpp')
-rw-r--r--Userland/Libraries/LibC/stdio.cpp7
1 files changed, 1 insertions, 6 deletions
diff --git a/Userland/Libraries/LibC/stdio.cpp b/Userland/Libraries/LibC/stdio.cpp
index 1338b82f4e..6411df4d79 100644
--- a/Userland/Libraries/LibC/stdio.cpp
+++ b/Userland/Libraries/LibC/stdio.cpp
@@ -1205,16 +1205,11 @@ void funlockfile([[maybe_unused]] FILE* filehandle)
FILE* tmpfile()
{
char tmp_path[] = "/tmp/XXXXXX";
- if (__generate_unique_filename(tmp_path) < 0)
- return nullptr;
-
- int fd = open(tmp_path, O_CREAT | O_EXCL | O_RDWR, S_IWUSR | S_IRUSR);
+ int fd = mkstemp(tmp_path);
if (fd < 0)
return nullptr;
-
// FIXME: instead of using this hack, implement with O_TMPFILE or similar
unlink(tmp_path);
-
return fdopen(fd, "rw");
}
}