diff options
author | Bin Meng <bin.meng@windriver.com> | 2022-10-10 12:04:31 +0800 |
---|---|---|
committer | Kevin Wolf <kwolf@redhat.com> | 2022-10-27 20:13:32 +0200 |
commit | 69fbfff95e849156985cf95e2010ffc8762e34e6 (patch) | |
tree | 1517329e87499effe15c69e372cff9b7efdb05f3 /include/block | |
parent | 6b6471eee11dce4c995419b68441c6637be3d90a (diff) | |
download | qemu-69fbfff95e849156985cf95e2010ffc8762e34e6.zip qemu-69fbfff95e849156985cf95e2010ffc8762e34e6.tar.gz qemu-69fbfff95e849156985cf95e2010ffc8762e34e6.tar.bz2 |
block: Refactor get_tmp_filename()
At present there are two callers of get_tmp_filename() and they are
inconsistent.
One does:
/* TODO: extra byte is a hack to ensure MAX_PATH space on Windows. */
char *tmp_filename = g_malloc0(PATH_MAX + 1);
...
ret = get_tmp_filename(tmp_filename, PATH_MAX + 1);
while the other does:
s->qcow_filename = g_malloc(PATH_MAX);
ret = get_tmp_filename(s->qcow_filename, PATH_MAX);
As we can see different 'size' arguments are passed. There are also
platform specific implementations inside the function, and the use
of snprintf is really undesirable.
The function name is also misleading. It creates a temporary file,
not just a filename.
Refactor this routine by changing its name and signature to:
char *create_tmp_file(Error **errp)
and use g_get_tmp_dir() / g_mkstemp() for a consistent implementation.
While we are here, add some comments to mention that /var/tmp is
preferred over /tmp on non-win32 hosts.
Signed-off-by: Bin Meng <bin.meng@windriver.com>
Message-Id: <20221010040432.3380478-2-bin.meng@windriver.com>
[kwolf: Fixed incorrect errno negation and iotest 051]
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Diffstat (limited to 'include/block')
-rw-r--r-- | include/block/block_int-common.h | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/include/block/block_int-common.h b/include/block/block_int-common.h index 8947aba..d7c0a7e 100644 --- a/include/block/block_int-common.h +++ b/include/block/block_int-common.h @@ -1230,7 +1230,7 @@ static inline BlockDriverState *child_bs(BdrvChild *child) } int bdrv_check_request(int64_t offset, int64_t bytes, Error **errp); -int get_tmp_filename(char *filename, int size); +char *create_tmp_file(Error **errp); void bdrv_parse_filename_strip_prefix(const char *filename, const char *prefix, QDict *options); |