From: Sami Kerola Date: Sun, 13 Jul 2014 16:40:31 +0000 (+0100) Subject: fdisk: avoid code duplication X-Git-Tag: v2.25~75^2~6 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=bbe67996ada5c9f689b650775ad5262081cf256e;p=thirdparty%2Futil-linux.git fdisk: avoid code duplication To me having call to close() twice is less readable than one new variable. Signed-off-by: Sami Kerola --- diff --git a/disk-utils/fdisk.c b/disk-utils/fdisk.c index e9b4fec506..d6bb737399 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; }