summaryrefslogtreecommitdiffstats
path: root/fdisks/fdisk.c
diff options
context:
space:
mode:
authorKarel Zak2013-09-26 10:58:03 +0200
committerKarel Zak2013-09-26 10:58:03 +0200
commit5afed1872e763b3171aad79c9f08dfa111ef76a1 (patch)
treefbc25d7200bed13088cada84864a89f4ecacbdaf /fdisks/fdisk.c
parentlibfdisk: (bds) cleanup includes (diff)
downloadkernel-qcow2-util-linux-5afed1872e763b3171aad79c9f08dfa111ef76a1.tar.gz
kernel-qcow2-util-linux-5afed1872e763b3171aad79c9f08dfa111ef76a1.tar.xz
kernel-qcow2-util-linux-5afed1872e763b3171aad79c9f08dfa111ef76a1.zip
fdisk: use xalloc stuff
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'fdisks/fdisk.c')
-rw-r--r--fdisks/fdisk.c20
1 files changed, 9 insertions, 11 deletions
diff --git a/fdisks/fdisk.c b/fdisks/fdisk.c
index 61a522c36..f8216bba9 100644
--- a/fdisks/fdisk.c
+++ b/fdisks/fdisk.c
@@ -45,8 +45,6 @@
# include <linux/blkpg.h>
#endif
-#include "fdisk.h"
-
static void __attribute__ ((__noreturn__)) usage(FILE *out)
{
fputs(USAGE_HEADER, out);
@@ -273,20 +271,20 @@ static void dump_buffer(off_t base, unsigned char *buf, size_t sz, int all)
static void dump_blkdev(struct fdisk_context *cxt, const char *name,
off_t offset, size_t size, int all)
{
- unsigned char *buf = NULL;
-
fdisk_colon(cxt, _("\n%s: offset = %ju, size = %zu bytes."),
name, offset, size);
if (lseek(cxt->dev_fd, offset, SEEK_SET) == (off_t) -1)
fdisk_warn(cxt, _("cannot seek"));
- else if (!(buf = malloc(size)))
- fdisk_warn(cxt, _("cannot allocate"));
- else if (read_all(cxt->dev_fd, (char *) buf, size) != (ssize_t) size)
- fdisk_warn(cxt, _("cannot read"));
- else
- dump_buffer(offset, buf, size, all);
- free(buf);
+ else {
+ unsigned char *buf = xmalloc(size);
+
+ if (read_all(cxt->dev_fd, (char *) buf, size) != (ssize_t) size)
+ fdisk_warn(cxt, _("cannot read"));
+ else
+ dump_buffer(offset, buf, size, all);
+ free(buf);
+ }
}
void dump_firstsector(struct fdisk_context *cxt)