[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 03/51] block: Unify the get_tmp_filename() implementation
From: |
Bin Meng |
Subject: |
[PATCH 03/51] block: Unify the get_tmp_filename() implementation |
Date: |
Wed, 24 Aug 2022 17:39:41 +0800 |
From: Bin Meng <bin.meng@windriver.com>
At present get_tmp_filename() has platform specific implementations
to get the directory to use for temporary files. Switch over to use
g_get_tmp_dir() which works on all supported platforms.
Signed-off-by: Bin Meng <bin.meng@windriver.com>
---
block.c | 16 ++--------------
1 file changed, 2 insertions(+), 14 deletions(-)
diff --git a/block.c b/block.c
index bc85f46eed..d06df47f72 100644
--- a/block.c
+++ b/block.c
@@ -864,21 +864,10 @@ int bdrv_probe_geometry(BlockDriverState *bs, HDGeometry
*geo)
*/
int get_tmp_filename(char *filename, int size)
{
-#ifdef _WIN32
- char temp_dir[MAX_PATH];
- /* GetTempFileName requires that its output buffer (4th param)
- have length MAX_PATH or greater. */
- assert(size >= MAX_PATH);
- return (GetTempPath(MAX_PATH, temp_dir)
- && GetTempFileName(temp_dir, "qem", 0, filename)
- ? 0 : -GetLastError());
-#else
int fd;
const char *tmpdir;
- tmpdir = getenv("TMPDIR");
- if (!tmpdir) {
- tmpdir = "/var/tmp";
- }
+ tmpdir = g_get_tmp_dir();
+
if (snprintf(filename, size, "%s/vl.XXXXXX", tmpdir) >= size) {
return -EOVERFLOW;
}
@@ -891,7 +880,6 @@ int get_tmp_filename(char *filename, int size)
return -errno;
}
return 0;
-#endif
}
/*
--
2.34.1
- [PATCH 00/51] tests/qtest: Enable running qtest on Windows, Bin Meng, 2022/08/24
- [PATCH 01/51] tests/qtest: Use g_setenv(), Bin Meng, 2022/08/24
- [PATCH 02/51] tests/qtest: Use g_mkdtemp(), Bin Meng, 2022/08/24
- [PATCH 03/51] block: Unify the get_tmp_filename() implementation,
Bin Meng <=
- [PATCH 04/51] semihosting/arm-compat-semi: Avoid using hardcoded /tmp, Bin Meng, 2022/08/24
- [PATCH 05/51] tcg: Avoid using hardcoded /tmp, Bin Meng, 2022/08/24
- [PATCH 06/51] util/qemu-sockets: Use g_get_tmp_dir() to get the directory for temporary files, Bin Meng, 2022/08/24
- [PATCH 09/51] fsdev/virtfs-proxy-helper: Use g_mkdir_with_parents(), Bin Meng, 2022/08/24