]> xenbits.xensource.com Git - libvirt.git/commitdiff
Replace truncate() with ftruncate()
authorDaniel P. Berrange <berrange@redhat.com>
Wed, 8 Feb 2012 14:03:29 +0000 (14:03 +0000)
committerDaniel P. Berrange <berrange@redhat.com>
Wed, 8 Feb 2012 19:50:15 +0000 (19:50 +0000)
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

index 8260adbd1f3e6bd0fa050bae638716467ff472e1..a8661e3b795293e5bb774865cbe17b23bbc181ea 100644 (file)
@@ -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__