[PATCH 08/14] fdisk: avoid code duplication

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



To me having call to close() twice is less readable than one new
variable.

Signed-off-by: Sami Kerola <kerolasa@xxxxxx>
---
 disk-utils/fdisk.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/disk-utils/fdisk.c b/disk-utils/fdisk.c
index e9b4fec..d6bb737 100644
--- a/disk-utils/fdisk.c
+++ b/disk-utils/fdisk.c
@@ -725,16 +725,15 @@ static void print_all_devices_pt(struct fdisk_context *cxt)
 
 static sector_t get_dev_blocks(char *dev)
 {
-	int fd;
+	int fd, ret;
 	sector_t size;
 
 	if ((fd = open(dev, O_RDONLY)) < 0)
 		err(EXIT_FAILURE, _("cannot open %s"), dev);
-	if (blkdev_get_sectors(fd, &size) == -1) {
-		close(fd);
-		err(EXIT_FAILURE, _("BLKGETSIZE ioctl failed on %s"), dev);
-	}
+	ret = blkdev_get_sectors(fd, &size);
 	close(fd);
+	if (ret < 0)
+		err(EXIT_FAILURE, _("BLKGETSIZE ioctl failed on %s"), dev);
 	return size/2;
 }
 
-- 
2.0.1

--
To unsubscribe from this list: send the line "unsubscribe util-linux" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux