flash_eraseall: do not use exit()
PATCH 1/1 flash_eraseall: do not use exit()
From: Ladislav Michl <[email protected]>
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 <[email protected]>
--- flash_eraseall.c | 42 ++++++++++++++++-------------------------- 1 file changed, 16 insertions(+), 26 deletions(-)
flash_eraseall.c +16 -26
@@ -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));
Quoted 2 lines · Ladislav Michl
Returning from
main()instead of usingexit()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