From: Mike Frysinger Date: Mon, 6 Jun 2011 18:22:14 +0000 (-0400) Subject: flash_info: convert to common.h X-Git-Tag: v1.4.5~21 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=a204ad243f4f07b757742ff30924e3fea0ec5d3e;p=mtd-utils.git flash_info: convert to common.h Signed-off-by: Mike Frysinger Signed-off-by: Artem Bityutskiy --- diff --git a/flash_info.c b/flash_info.c index f8b7efa..d4887da 100644 --- a/flash_info.c +++ b/flash_info.c @@ -12,24 +12,31 @@ #include #include +#include "common.h" #include +static void usage(int status) +{ + fprintf(status ? stderr : stdout, + "Usage: %s \n", + PROGRAM_NAME); + exit(status); +} + int main(int argc, char *argv[]) { int regcount; int fd; - if (1 >= argc) { - fprintf(stderr, "Usage: %s device\n", PROGRAM_NAME); - return 16; - } + if (argc < 2) + usage(1); + if (!strcmp(argv[1], "-h") || !strcmp(argv[1], "--help")) + usage(0); /* Open and size the device */ fd = open(argv[1], O_RDONLY); - if (fd < 0) { - fprintf(stderr, "File open error\n"); - return 8; - } + if (fd < 0) + sys_errmsg_die("could not open: %s", argv[1]); if (ioctl(fd, MEMGETREGIONCOUNT, ®count) == 0) { int i; @@ -42,8 +49,8 @@ int main(int argc, char *argv[]) "has 0x%x blocks\n", i, reginfo.offset, reginfo.erasesize, reginfo.numblocks); } else { - printf("Strange can not read region %d from a %d region device\n", - i, regcount); + warnmsg("can not read region %d from a %d region device", + i, regcount); } } }