summaryrefslogtreecommitdiff
path: root/test/tmpfile.h
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2024-12-07 17:14:45 +0100
committerBent Bisballe Nyeng <deva@aasimon.org>2024-12-21 16:21:49 +0100
commitd2e7188e33a58cab05ef6292795303ad4b92a5f7 (patch)
treea6789fb724833d4d800626bf9b4707fa4ae1e9d8 /test/tmpfile.h
parente166206702c8dbd3162452cf26f368e856ac0138 (diff)
WIPmsvc
Diffstat (limited to 'test/tmpfile.h')
-rw-r--r--test/tmpfile.h16
1 files changed, 13 insertions, 3 deletions
diff --git a/test/tmpfile.h b/test/tmpfile.h
index 5d114d0..e1a2ff6 100644
--- a/test/tmpfile.h
+++ b/test/tmpfile.h
@@ -4,7 +4,6 @@
#pragma once
#include <cstdlib>
-#include <unistd.h>
#ifdef _WIN32
#define WIN32_LEAN_AND_MEAN
@@ -12,6 +11,9 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
+#include <io.h>
+#else
+#include <unistd.h>
#endif
struct tmp_file
@@ -22,20 +24,28 @@ struct tmp_file
#ifdef _WIN32
char templ[] = "ctor_tmp_file-XXXXXX"; // buffer for filename
_mktemp_s(templ, sizeof(templ));
- fd = open(templ, O_CREAT | O_RDWR);
+ fd = _open(templ, O_CREAT | O_RDWR);
+ filename = templ;
+ auto sz = _write(fd, data.data(), data.size());
+ (void)sz;
+ _close(fd);
#else
char templ[] = "/tmp/ctor_tmp_file-XXXXXX"; // buffer for filename
fd = mkstemp(templ);
-#endif
filename = templ;
auto sz = write(fd, data.data(), data.size());
(void)sz;
close(fd);
+#endif
}
~tmp_file()
{
+#ifdef _WIN32
+ _unlink(filename.data());
+#else
unlink(filename.data());
+#endif
}
const std::string& get() const