mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-24 22:55:23 +00:00
Replace truncate() with ftruncate()
Mingw32 does not have any truncate() API defined, but it does have ftruncate(). So replace use of the former with the latter
This commit is contained in:
parent
21fe874832
commit
bc6bb3a3e8
@ -939,12 +939,29 @@ virStorageFileFreeMetadata(virStorageFileMetadata *meta)
|
|||||||
int
|
int
|
||||||
virStorageFileResize(const char *path, unsigned long long capacity)
|
virStorageFileResize(const char *path, unsigned long long capacity)
|
||||||
{
|
{
|
||||||
if (truncate(path, capacity) < 0) {
|
int fd = -1;
|
||||||
virReportSystemError(errno, _("Failed to truncate file '%s'"), path);
|
int ret = -1;
|
||||||
return -1;
|
|
||||||
|
if ((fd = open(path, O_RDWR)) < 0) {
|
||||||
|
virReportSystemError(errno, _("Unable to open '%s'"), path);
|
||||||
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
if (ftruncate(fd, capacity) < 0) {
|
||||||
|
virReportSystemError(errno, _("Failed to truncate file '%s'"), path);
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (VIR_CLOSE(fd) < 0) {
|
||||||
|
virReportSystemError(errno, _("Unable to save '%s'"), path);
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = 0;
|
||||||
|
|
||||||
|
cleanup:
|
||||||
|
VIR_FORCE_CLOSE(fd);
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
|
Loading…
Reference in New Issue
Block a user