提交 bc6bb3a3 编写于 作者: D Daniel P. Berrange

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
上级 21fe8748
......@@ -939,12 +939,29 @@ virStorageFileFreeMetadata(virStorageFileMetadata *meta)
int
virStorageFileResize(const char *path, unsigned long long capacity)
{
if (truncate(path, capacity) < 0) {
int fd = -1;
int ret = -1;
if ((fd = open(path, O_RDWR)) < 0) {
virReportSystemError(errno, _("Unable to open '%s'"), path);
goto cleanup;
}
if (ftruncate(fd, capacity) < 0) {
virReportSystemError(errno, _("Failed to truncate file '%s'"), path);
return -1;
goto cleanup;
}
return 0;
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__
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册