aboutsummaryrefslogtreecommitdiff
path: root/src/os.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/os.cpp')
-rw-r--r--src/os.cpp12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/os.cpp b/src/os.cpp
index 95febca9bc..f52325af00 100644
--- a/src/os.cpp
+++ b/src/os.cpp
@@ -1232,6 +1232,18 @@ static Error os_buf_to_tmp_file_posix(Buf *contents, Buf *suffix, Buf *out_tmp_p
}
#endif
+Buf *os_tmp_filename(Buf *prefix, Buf *suffix) {
+ Buf *result = buf_create_from_buf(prefix);
+
+ const char base64[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_";
+ assert(array_length(base64) == 64 + 1);
+ for (size_t i = 0; i < 12; i += 1) {
+ buf_append_char(result, base64[rand() % 64]);
+ }
+ buf_append_buf(result, suffix);
+ return result;
+}
+
#if defined(ZIG_OS_WINDOWS)
static Error os_buf_to_tmp_file_windows(Buf *contents, Buf *suffix, Buf *out_tmp_path) {
char tmp_dir[MAX_PATH + 1];