summaryrefslogtreecommitdiffstats
path: root/disk-utils/fdisk.c
diff options
context:
space:
mode:
authorSami Kerola2014-07-13 18:40:31 +0200
committerSami Kerola2014-07-13 19:35:38 +0200
commitbbe67996ada5c9f689b650775ad5262081cf256e (patch)
tree5f2e8af91044db39df17986760ef5869dfc0689a /disk-utils/fdisk.c
parentmkfs.cramfs: use defined failure name rather than magic value (diff)
downloadkernel-qcow2-util-linux-bbe67996ada5c9f689b650775ad5262081cf256e.tar.gz
kernel-qcow2-util-linux-bbe67996ada5c9f689b650775ad5262081cf256e.tar.xz
kernel-qcow2-util-linux-bbe67996ada5c9f689b650775ad5262081cf256e.zip
fdisk: avoid code duplication
To me having call to close() twice is less readable than one new variable. Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Diffstat (limited to 'disk-utils/fdisk.c')
-rw-r--r--disk-utils/fdisk.c9
1 files changed, 4 insertions, 5 deletions
diff --git a/disk-utils/fdisk.c b/disk-utils/fdisk.c
index e9b4fec50..d6bb73739 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;
}