linux-mtd.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: Ladislav Michl <Ladislav.Michl@seznam.cz>
To: linux-mtd@lists.infradead.org
Subject: [PATCH] flash_eraseall: do not use exit()
Date: Wed, 23 Jun 2010 12:48:58 +0200	[thread overview]
Message-ID: <20100623104858.GA2442@localhost.localdomain> (raw)

From: Ladislav Michl <ladis@linux-mips.org>

Returning from main() instead of using exit() makes code more readable
and smaller.

   text    data     bss     dec     hex filename
   6440     324      68    6832    1ab0 flash_eraseall
   6405     320      68    6793    1a89 flash_eraseall.noexit

Signed-off-by: Ladislav Michl <ladis@linux-mips.org>
---
 flash_eraseall.c |   42 ++++++++++++++++--------------------------
 1 file changed, 16 insertions(+), 26 deletions(-)

diff --git a/flash_eraseall.c b/flash_eraseall.c
index 531bbe6..db65553 100644
--- a/flash_eraseall.c
+++ b/flash_eraseall.c
@@ -51,14 +51,6 @@ static int jffs2;		/* format for jffs2 usage */
 static struct jffs2_unknown_node cleanmarker;
 int target_endian = __BYTE_ORDER;
 
-static void show_progress(mtd_info_t *meminfo, erase_info_t *erase)
-{
-	printf("\rErasing %d Kibyte @ %x -- %2llu %% complete.",
-		meminfo->erasesize / 1024, erase->start,
-		(unsigned long long) erase->start * 100 / meminfo->size);
-	fflush(stdout);
-}
-
 static void display_help(void)
 {
 	printf("Usage: %s [OPTION] MTD_DEVICE\n"
@@ -70,10 +62,8 @@ static void display_help(void)
 			"      --help     display this help and exit\n"
 			"      --version  output version information and exit\n",
 			exe_name);
-	exit(0);
 }
 
-
 static void display_version(void)
 {
 	printf(PROGRAM " " VERSION "\n"
@@ -86,12 +76,22 @@ static void display_version(void)
 			"You may redistribute copies of " PROGRAM "\n"
 			"under the terms of the GNU General Public Licence.\n"
 			"See the file `COPYING' for more information.\n");
-	exit(0);
 }
 
-static void process_options(int argc, char *argv[])
+static void show_progress(mtd_info_t *meminfo, erase_info_t *erase)
+{
+	printf("\rErasing %d Kibyte @ %x -- %2llu %% complete.",
+		meminfo->erasesize / 1024, erase->start,
+		(unsigned long long) erase->start * 100 / meminfo->size);
+	fflush(stdout);
+}
+
+int main(int argc, char *argv[])
 {
-	int error = 0;
+	mtd_info_t meminfo;
+	int fd, error = 0, clmpos = 0, clmlen = 8;
+	erase_info_t erase;
+	int isNAND, bbtest = 1;
 
 	exe_name = argv[0];
 
@@ -119,10 +119,10 @@ static void process_options(int argc, char *argv[])
 				switch (option_index) {
 					case 0:
 						display_help();
-						break;
+						return 0;
 					case 1:
 						display_version();
-						break;
+						return 0;
 				}
 				break;
 			case 'q':
@@ -143,20 +143,10 @@ static void process_options(int argc, char *argv[])
 	if (error) {
 		fprintf(stderr, "Try `%s --help' for more information.\n",
 				exe_name);
-		exit(1);
+		return 1;
 	}
 
 	mtd_device = argv[optind];
-}
-
-int main(int argc, char *argv[])
-{
-	mtd_info_t meminfo;
-	int fd, clmpos = 0, clmlen = 8;
-	erase_info_t erase;
-	int isNAND, bbtest = 1;
-
-	process_options(argc, argv);
 
 	if ((fd = open(mtd_device, O_RDWR)) < 0) {
 		fprintf(stderr, "%s: %s: %s\n", exe_name, mtd_device, strerror(errno));

             reply	other threads:[~2010-06-23  8:49 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-06-23 10:48 Ladislav Michl [this message]
2010-06-23 11:13 ` [PATCH] flash_eraseall: do not use exit() Ladislav Michl

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20100623104858.GA2442@localhost.localdomain \
    --to=ladislav.michl@seznam.cz \
    --cc=ladis@linux-mips.org \
    --cc=linux-mtd@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).