]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
util: file: use VIR_AUTOCLOSE instead of VIR_FORCE_CLOSE
authorShi Lei <shi_lei@massclouds.com>
Wed, 12 Sep 2018 09:46:36 +0000 (17:46 +0800)
committerMichal Privoznik <mprivozn@redhat.com>
Wed, 12 Sep 2018 15:35:38 +0000 (17:35 +0200)
Signed-off-by: Shi Lei <shi_lei@massclouds.com>
src/util/virfile.c

index 01ebdb6f49303c439a32d625f04f7bc05464307d..2366c119fd228397f6a174f7eaddafcf2f771f53 100644 (file)
@@ -1969,29 +1969,22 @@ int
 virFileIsCDROM(const char *path)
 {
     struct stat st;
-    int fd;
-    int ret = -1;
+    VIR_AUTOCLOSE fd = -1;
 
     if ((fd = open(path, O_RDONLY | O_NONBLOCK)) < 0)
-        goto cleanup;
+        return -1;
 
     if (fstat(fd, &st) < 0)
-        goto cleanup;
+        return -1;
 
-    if (!S_ISBLK(st.st_mode)) {
-        ret = 0;
-        goto cleanup;
-    }
+    if (!S_ISBLK(st.st_mode))
+        return 0;
 
     /* Attempt to detect via a CDROM specific ioctl */
     if (ioctl(fd, CDROM_DRIVE_STATUS, CDSL_CURRENT) >= 0)
-        ret = 1;
-    else
-        ret = 0;
+        return 1;
 
- cleanup:
-    VIR_FORCE_CLOSE(fd);
-    return ret;
+    return 0;
 }
 
 #else