Patchwork flash_eraseall: do not use exit()

login
register
mail settings
Submitter Ladislav Michl
Date June 23, 2010, 10:48 a.m.
Message ID <20100623104858.GA2442@localhost.localdomain>
Download mbox | patch
Permalink /patch/56615/
State New
Headers show

Comments

Ladislav Michl - June 23, 2010, 10:48 a.m.
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(-)
Ladislav Michl - June 23, 2010, 11:13 a.m.
On Wed, Jun 23, 2010 at 12:48:58PM +0200, Ladislav Michl wrote:
> Returning from main() instead of using exit() makes code more readable
> and smaller.

Please disregard, I'll send update based on Stanley's patches, which looks
really good and I'm just testing them...

	ladis

Patch

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));