public inbox for linux-mtd@lists.infradead.org
 help / color / mirror / Atom feed
* [PATCH 1/4] flash_info: convert to common.h
@ 2011-06-06 18:22 Mike Frysinger
  2011-06-06 18:22 ` [PATCH 2/4] flash_info: allow people to get info on multiple devices Mike Frysinger
                   ` (3 more replies)
  0 siblings, 4 replies; 16+ messages in thread
From: Mike Frysinger @ 2011-06-06 18:22 UTC (permalink / raw)
  To: linux-mtd

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
---
 flash_info.c |   27 +++++++++++++++++----------
 1 files changed, 17 insertions(+), 10 deletions(-)

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 <sys/ioctl.h>
 #include <sys/mount.h>
 
+#include "common.h"
 #include <mtd/mtd-user.h>
 
+static void usage(int status)
+{
+	fprintf(status ? stderr : stdout,
+		"Usage: %s <device>\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, &regcount) == 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);
 			}
 		}
 	}
-- 
1.7.5.3

^ permalink raw reply related	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2011-06-07  5:22 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-06-06 18:22 [PATCH 1/4] flash_info: convert to common.h Mike Frysinger
2011-06-06 18:22 ` [PATCH 2/4] flash_info: allow people to get info on multiple devices Mike Frysinger
2011-06-06 18:22 ` [PATCH 3/4] include/mtd: sync with kernel Mike Frysinger
2011-06-06 18:47   ` Brian Norris
2011-06-06 18:22 ` [PATCH 4/4] flash_info: display MEMGETINFO and MEMISLOCKED Mike Frysinger
2011-06-07  5:01   ` Artem Bityutskiy
2011-06-07  5:05     ` Artem Bityutskiy
2011-06-07  5:14     ` Mike Frysinger
2011-06-07  5:11       ` Artem Bityutskiy
2011-06-07  5:18       ` Artem Bityutskiy
2011-06-07  4:31 ` [PATCH 1/4] flash_info: convert to common.h Artem Bityutskiy
2011-06-07  4:41   ` Mike Frysinger
2011-06-07  4:42     ` Artem Bityutskiy
2011-06-07  4:45       ` Artem Bityutskiy
2011-06-07  4:51         ` Mike Frysinger
2011-06-07  5:01           ` Artem Bityutskiy

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox