[libvirt] [PATCH] Replace truncate() with ftruncate()

From: "Daniel P. Berrange" <berrange@redhat.com> Mingw32 does not have any truncate() API defined, but it does have ftruncate(). So replace use of the former with the latter --- src/util/storage_file.c | 23 ++++++++++++++++++++--- 1 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/util/storage_file.c b/src/util/storage_file.c index 8260adb..a8661e3 100644 --- a/src/util/storage_file.c +++ b/src/util/storage_file.c @@ -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__ -- 1.7.7.6

On 02/08/2012 07:04 AM, Daniel P. Berrange wrote:
From: "Daniel P. Berrange" <berrange@redhat.com>
Mingw32 does not have any truncate() API defined, but it does have ftruncate(). So replace use of the former with the latter
Hmm, maybe we should also be pulling in the gnulib ftruncate module (since mingw has ftruncate but not MSVC 9). And gnulib could probably implement a truncate module, but not in time for 0.9.10.
--- src/util/storage_file.c | 23 ++++++++++++++++++++--- 1 files changed, 20 insertions(+), 3 deletions(-)
ACK. -- Eric Blake eblake@redhat.com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
participants (2)
-
Daniel P. Berrange
-
Eric Blake