From efda21ca931766eed6cfc49d1b2122c53827d9fc Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Thu, 29 Nov 2007 18:14:37 -0600 Subject: Change command main() functions to return void, and exit(toys.exitval) from the toybox infrastructure instead. Eliminates a return call from each command. --- toys/basename.c | 3 +-- toys/bzcat.c | 4 +--- toys/catv.c | 8 +++----- toys/count.c | 3 +-- toys/df.c | 4 +--- toys/dirname.c | 3 +-- toys/dmesg.c | 8 +++----- toys/echo.c | 3 +-- toys/false.c | 4 ++-- toys/hello.c | 3 +-- toys/help.c | 3 +-- toys/mdev.c | 6 ++---- toys/mke2fs.c | 4 +--- toys/mkfifo.c | 4 +--- toys/oneit.c | 4 ++-- toys/pwd.c | 4 +--- toys/readlink.c | 7 ++----- toys/sha1.c | 2 +- toys/sleep.c | 4 ++-- toys/sync.c | 3 +-- toys/touch.c | 4 +--- toys/toylist.h | 4 ++-- toys/toysh.c | 14 +++++++------- toys/true.c | 4 ++-- toys/tty.c | 4 ++-- toys/which.c | 12 ++++-------- toys/yes.c | 4 +--- 27 files changed, 48 insertions(+), 82 deletions(-) (limited to 'toys') diff --git a/toys/basename.c b/toys/basename.c index da843b86..ee5345e4 100644 --- a/toys/basename.c +++ b/toys/basename.c @@ -6,7 +6,7 @@ #include "toys.h" -int basename_main(void) +void basename_main(void) { char *name = basename(*toys.optargs); char *suffix = toys.optargs[1]; @@ -15,5 +15,4 @@ int basename_main(void) if (end>name && !strcmp(end,suffix)) *end=0; } puts(name); - return 0; } diff --git a/toys/bzcat.c b/toys/bzcat.c index 348a5939..984e4186 100644 --- a/toys/bzcat.c +++ b/toys/bzcat.c @@ -5,9 +5,7 @@ #include "toys.h" -int bzcat_main(void) +void bzcat_main(void) { bunzipStream(0, 1); - - return 0; } diff --git a/toys/catv.c b/toys/catv.c index 74242010..e5412700 100644 --- a/toys/catv.c +++ b/toys/catv.c @@ -34,21 +34,19 @@ void do_catv(int fd, char *name) } if (c < 32) { if (c == 10) { - if (toys.optflags & 1) putchar('$'); + if (toys.optflags & 1) xputc('$'); } else if (toys.optflags & (c==9 ? 2 : 4)) { printf("^%c", c+'@'); continue; } } - putchar(c); + xputc(c); } } } -int catv_main(void) +void catv_main(void) { toys.optflags^=4; loopfiles(toys.optargs, do_catv); - - return toys.exitval; } diff --git a/toys/count.c b/toys/count.c index d7c05ce7..901962b2 100644 --- a/toys/count.c +++ b/toys/count.c @@ -5,7 +5,7 @@ #include "toys.h" -int count_main(void) +void count_main(void) { uint64_t size = 0; int len; @@ -18,5 +18,4 @@ int count_main(void) fdprintf(2, "%"PRIu64" bytes\r", size); } fdprintf(2,"\n"); - return 0; } diff --git a/toys/df.c b/toys/df.c index ffff6ce4..52863cc7 100644 --- a/toys/df.c +++ b/toys/df.c @@ -55,7 +55,7 @@ static void show_mt(struct mtab_list *mt) } } -int df_main(void) +void df_main(void) { struct mtab_list *mt, *mt2, *mtlist; @@ -114,6 +114,4 @@ int df_main(void) } if (CFG_TOYBOX_FREE) llist_free(mtlist, NULL); - - return 0; } diff --git a/toys/dirname.c b/toys/dirname.c index b33836b6..8810bec5 100644 --- a/toys/dirname.c +++ b/toys/dirname.c @@ -7,8 +7,7 @@ #include "toys.h" #include -int dirname_main(void) +void dirname_main(void) { puts(dirname(*toys.optargs)); - return 0; } diff --git a/toys/dmesg.c b/toys/dmesg.c index 7a150121..59343897 100644 --- a/toys/dmesg.c +++ b/toys/dmesg.c @@ -10,7 +10,7 @@ #define TT toy.dmesg -int dmesg_main(void) +void dmesg_main(void) { // For -n just tell kernel to which messages to keep. if (toys.optflags & 2) { @@ -30,11 +30,9 @@ int dmesg_main(void) // Display data, filtering out level markers. for (i=0; iargv); - cmd->pid = tl->toy_main(); + tl->toy_main(); + cmd->pid = toys.exitval; free(toys.optargs); memcpy(&toys, &temp, sizeof(struct toy_context)); } else { @@ -184,19 +185,18 @@ static void handle(char *command) } } -int cd_main(void) +void cd_main(void) { char *dest = *toys.optargs ? *toys.optargs : getenv("HOME"); if (chdir(dest)) error_exit("chdir %s",dest); - return 0; } -int exit_main(void) +void exit_main(void) { exit(*toys.optargs ? atoi(*toys.optargs) : 0); } -int toysh_main(void) +void toysh_main(void) { FILE *f; @@ -210,12 +210,12 @@ int toysh_main(void) size_t cmdlen = 0; for (;;) { char *command = 0; - if (!f) putchar('$'); + if (!f) xputc('$'); if (1 > getline(&command, &cmdlen, f ? : stdin)) break; handle(command); free(command); } } - return 1; + toys.exitval = 1; } diff --git a/toys/true.c b/toys/true.c index 49ec11bf..6e40eb14 100644 --- a/toys/true.c +++ b/toys/true.c @@ -5,7 +5,7 @@ #include "toys.h" -int true_main(void) +void true_main(void) { - return 0; + return; } diff --git a/toys/tty.c b/toys/tty.c index d04e3012..3dfba9ee 100644 --- a/toys/tty.c +++ b/toys/tty.c @@ -6,12 +6,12 @@ #include "toys.h" -int tty_main(void) +void tty_main(void) { char *name = ttyname(0); if (!toys.optflags) { if (name) puts(name); else puts("Not a tty"); } - return !name; + toys.exitval = !name; } diff --git a/toys/which.c b/toys/which.c index 546bdcca..c01f3bb3 100644 --- a/toys/which.c +++ b/toys/which.c @@ -52,16 +52,12 @@ static int which_in_path(char *filename) return 0; } -int which_main(void) +void which_main(void) { - int rc = 0; - - if (!*toys.optargs) rc++; + if (!*toys.optargs) toys.exitval++; else { int i; - for (i=0; toys.optargs[i]; i++) rc |= which_in_path(toys.optargs[i]); + for (i=0; toys.optargs[i]; i++) + toys.exitval |= which_in_path(toys.optargs[i]); } - // if (CFG_TOYBOX_FREE) free(argv); - - return rc; } diff --git a/toys/yes.c b/toys/yes.c index 6f2c6a3d..0b48929e 100644 --- a/toys/yes.c +++ b/toys/yes.c @@ -5,7 +5,7 @@ #include "toys.h" -int yes_main(void) +void yes_main(void) { for (;;) { int i; @@ -16,6 +16,4 @@ int yes_main(void) if (!i) xputc('y'); xputc('\n'); } - - return 0; } -- cgit v1.2.3