diff options
Diffstat (limited to 'coreutils')
-rw-r--r-- | coreutils/cat.c | 8 | ||||
-rw-r--r-- | coreutils/chown.c | 12 | ||||
-rw-r--r-- | coreutils/chroot.c | 20 | ||||
-rw-r--r-- | coreutils/cp.c | 10 | ||||
-rw-r--r-- | coreutils/date.c | 172 | ||||
-rw-r--r-- | coreutils/pwd.c | 8 |
6 files changed, 106 insertions, 124 deletions
diff --git a/coreutils/cat.c b/coreutils/cat.c index 0f2460e..8718c4d 100644 --- a/coreutils/cat.c +++ b/coreutils/cat.c @@ -29,9 +29,9 @@ extern int cat_more_main(int argc, char **argv) int c; FILE *file = stdin; - if (argc < 2) { + if ( (argc < 2) || (**(argv+1) == '-') ) { fprintf(stderr, "Usage: %s %s", *argv, cat_usage); - return(FALSE); + exit(FALSE); } argc--; argv++; @@ -40,7 +40,7 @@ extern int cat_more_main(int argc, char **argv) file = fopen(*argv, "r"); if (file == NULL) { perror(*argv); - return(FALSE); + exit(FALSE); } while ((c = getc(file)) != EOF) putc(c, stdout); @@ -50,5 +50,5 @@ extern int cat_more_main(int argc, char **argv) argc--; argv++; } - return(TRUE); + exit(TRUE); } diff --git a/coreutils/chown.c b/coreutils/chown.c index 5ac48f7..bcaeea3 100644 --- a/coreutils/chown.c +++ b/coreutils/chown.c @@ -66,7 +66,7 @@ int chown_main(int argc, char **argv) if (argc < 2) { fprintf(stderr, "Usage: %s %s", *argv, (chownApp==TRUE)? chown_usage : chgrp_usage); - return( FALSE); + exit( FALSE); } invocationName=*argv; argc--; @@ -80,7 +80,7 @@ int chown_main(int argc, char **argv) break; default: fprintf(stderr, "Unknown option: %c\n", **argv); - return( FALSE); + exit( FALSE); } argc--; argv++; @@ -95,7 +95,7 @@ int chown_main(int argc, char **argv) grp = getgrnam(groupName); if (grp == NULL) { fprintf(stderr, "%s: Unknown group name: %s\n", invocationName, groupName); - return( FALSE); + exit( FALSE); } gid = grp->gr_gid; @@ -104,7 +104,7 @@ int chown_main(int argc, char **argv) pwd = getpwnam(*argv); if (pwd == NULL) { fprintf(stderr, "%s: Unknown user name: %s\n", invocationName, *argv); - return( FALSE); + exit( FALSE); } uid = pwd->pw_uid; } @@ -112,11 +112,11 @@ int chown_main(int argc, char **argv) /* Ok, ready to do the deed now */ if (argc <= 1) { fprintf(stderr, "%s: too few arguments", invocationName); - return( FALSE); + exit( FALSE); } while (argc-- > 1) { argv++; recursiveAction( *argv, recursiveFlag, TRUE, fileAction, fileAction); } - return(TRUE); + exit(TRUE); } diff --git a/coreutils/chroot.c b/coreutils/chroot.c index d395494..3b6fdae 100644 --- a/coreutils/chroot.c +++ b/coreutils/chroot.c @@ -20,8 +20,9 @@ */ #include "internal.h" +#include <stdlib.h> #include <stdio.h> -#include <unistd.h> +#include <errno.h> static const char chroot_usage[] = "NEWROOT [COMMAND...]\n" @@ -31,18 +32,17 @@ static const char chroot_usage[] = "NEWROOT [COMMAND...]\n" int chroot_main(int argc, char **argv) { - if (argc < 2) { + if ( (argc < 2) || (**(argv+1) == '-') ) { fprintf(stderr, "Usage: %s %s", *argv, chroot_usage); - return( FALSE); + exit( FALSE); } argc--; argv++; - fprintf(stderr, "new root: %s\n", *argv); - if (chroot (*argv) || (chdir ("/"))) { - perror("cannot chroot"); - return( FALSE); + fprintf(stderr, "chroot: cannot change root directory to %s: %s\n", + *argv, strerror(errno)); + exit( FALSE); } argc--; @@ -56,10 +56,10 @@ int chroot_main(int argc, char **argv) prog = getenv ("SHELL"); if (!prog) prog = "/bin/sh"; - fprintf(stderr, "no command. running: %s\n", prog); execlp (prog, prog, NULL); } - perror("cannot exec"); - return(FALSE); + fprintf(stderr, "chroot: cannot execute %s: %s\n", + *argv, strerror(errno)); + exit( FALSE); } diff --git a/coreutils/cp.c b/coreutils/cp.c index 797663d..4cdfc84 100644 --- a/coreutils/cp.c +++ b/coreutils/cp.c @@ -91,7 +91,7 @@ extern int cp_main(int argc, char **argv) if (argc < 3) { fprintf(stderr, "Usage: %s", cp_usage); - return (FALSE); + exit (FALSE); } argc--; argv++; @@ -129,13 +129,13 @@ extern int cp_main(int argc, char **argv) if ((argc > 3) && !dirFlag) { fprintf(stderr, "%s: not a directory\n", destName); - return (FALSE); + exit (FALSE); } while (argc-- >= 2) { srcName = *(argv++); - return recursiveAction(srcName, recursiveFlag, followLinks, - fileAction, fileAction); + exit( recursiveAction(srcName, recursiveFlag, followLinks, + fileAction, fileAction)); } - return( TRUE); + exit( TRUE); } diff --git a/coreutils/date.c b/coreutils/date.c index 5585170..2df9e0c 100644 --- a/coreutils/date.c +++ b/coreutils/date.c @@ -1,3 +1,24 @@ +/* + * Mini date implementation for busybox + * + * Copyright (C) 1999 by Erik Andersen <andersee@debian.org> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * +*/ + #include "internal.h" #include <stdlib.h> #include <errno.h> @@ -5,7 +26,6 @@ #include <unistd.h> #include <time.h> #include <stdio.h> -#include <getopt.h> /* This 'date' command supports only 2 time setting formats, @@ -14,25 +34,12 @@ an RFC 822 complient date output for shell scripting mail commands */ -const char date_usage[] = "date [-uR] [+FORMAT|+%f] [ [-s|-d] MMDDhhmm[[CC]YY]\n" -"| [[[[CCYY.]MM.DD-]hh:mm[:ss]]]] ]"; - -//static const char date_usage[] = "Usage: date [OPTION]... [+FORMAT]\n" -//"or: date [OPTION] [MMDDhhmm[[CC]YY][.ss]]\n" -//"Display the current time in the given FORMAT, or set the system date.\n"; - - -static struct option const long_options[] = -{ - {"date", required_argument, NULL, 'd'}, - /* {"rfc-822", no_argument, NULL, 'R'}, - {"set", required_argument, NULL, 's'}, - {"uct", no_argument, NULL, 'u'}, - {"utc", no_argument, NULL, 'u'}, - {"universal", no_argument, NULL, 'u'}, */ - {NULL, 0, NULL, 0} -}; - +const char date_usage[] = "Usage: date [OPTION]... [+FORMAT]\n" +" or: date [OPTION] [MMDDhhmm[[CC]YY][.ss]]\n" +"Display the current time in the given FORMAT, or set the system date.\n" +"\nOptions:\n\t-R\t\toutput RFC-822 compliant date string\n" +"\t-s\t\tset time described by STRING\n" +"\t-u\t\tprint or set Coordinated Universal Time\n"; /* Input parsing code is always bulky - used heavy duty libc stuff as @@ -53,7 +60,7 @@ date_conv_time(struct tm *tm_time, const char *t_string) { if(nr < 4 || nr > 5) { fprintf(stderr, "date: invalid date `%s'\n", t_string); - exit(1); + exit( FALSE); } /* correct for century - minor Y2K problem here? */ @@ -147,15 +154,15 @@ date_conv_ftime(struct tm *tm_time, const char *t_string) { fprintf(stderr, "date: invalid date `%s'\n", t_string); - exit(1); + exit( FALSE); } void date_err(void) { - fprintf(stderr, "date: only one date argument can be given at a time.\n"); - exit(1); + fprintf (stderr, "%s\n", date_usage); + exit( FALSE); } int @@ -164,82 +171,56 @@ date_main(int argc, char * * argv) char *date_str = NULL; char *date_fmt = NULL; char *t_buff; + int i; int set_time = 0; int rfc822 = 0; int utc = 0; int use_arg = 0; - int n_args; time_t tm; struct tm tm_time; - char optc; /* Interpret command line args */ - - - while ((optc = getopt_long (argc, argv, "d:Rs:u", long_options, NULL)) - != EOF) { - switch (optc) { - case 0: - break; - - case 'R': - rfc822 = 1; - break; - - case 's': - set_time = 1; - if(date_str != NULL) date_err(); - date_str = optarg; - break; - - case 'u': - utc = 1; - if (putenv ("TZ=UTC0") != 0) { - fprintf(stderr,"date: memory exhausted\n"); - return(1); - } -#if LOCALTIME_CACHE - tzset (); -#endif break; - - case 'd': - use_arg = 1; - if(date_str != NULL) date_err(); - date_str = optarg; - break; - - default: - fprintf(stderr, "Usage: %s", date_usage); - break; + i = --argc; + argv++; + while (i > 0 && **argv) { + if (**argv == '-') { + while (i>0 && *++(*argv)) switch (**argv) { + case 'R': + rfc822 = 1; + break; + case 's': + set_time = 1; + if(date_str != NULL) date_err(); + date_str = optarg; + break; + case 'u': + utc = 1; + if (putenv ("TZ=UTC0") != 0) { + fprintf(stderr,"date: memory exhausted\n"); + exit( FALSE); + } + /* Look ma, no break. Don't fix it either. */ + case 'd': + use_arg = 1; + if(date_str != NULL) date_err(); + date_str = optarg; + break; + case '-': + date_err(); + } + } else { + if ( (date_fmt == NULL) && (strcmp(*argv, "+")==0) ) + date_fmt=*argv; + else if (date_str == NULL) { + set_time = 1; + date_str=*argv; + } else { + date_err(); + } + } + i--; + argv++; } - } - - - n_args = argc - optind; - - while (n_args--){ - switch(argv[optind][0]) { - case '+': - /* Date format strings */ - if(date_fmt != NULL) { - fprintf(stderr, "date: only one date format can be given.\n"); - return(1); - } - date_fmt = &argv[optind][1]; - break; - - case '\0': - break; - - default: - /* Anything left over must be a date string to set the time */ - set_time = 1; - if(date_str != NULL) date_err(); - date_str = argv[optind]; - break; - } - optind++; - } /* Now we have parsed all the information except the date format @@ -267,14 +248,14 @@ date_main(int argc, char * * argv) tm = mktime(&tm_time); if (tm < 0 ) { fprintf(stderr, "date: invalid date `%s'\n", date_str); - exit(1); + exit( FALSE); } /* if setting time, set it */ if(set_time) { if( stime(&tm) < 0) { fprintf(stderr, "date: can't set date.\n"); - exit(1); + exit( FALSE); } } } @@ -292,7 +273,7 @@ date_main(int argc, char * * argv) } else if ( *date_fmt == '\0' ) { /* Imitate what GNU 'date' does with NO format string! */ printf ("\n"); - return(0); + exit( TRUE); } /* Handle special conversions */ @@ -306,6 +287,7 @@ date_main(int argc, char * * argv) strftime(t_buff, 200, date_fmt, &tm_time); printf("%s\n", t_buff); - return(0); + exit( TRUE); } + diff --git a/coreutils/pwd.c b/coreutils/pwd.c index d9ab54e..893ed1e 100644 --- a/coreutils/pwd.c +++ b/coreutils/pwd.c @@ -4,15 +4,15 @@ const char pwd_usage[] = "Print the current directory.\n"; extern int -pwd_main(struct FileInfo * i, int argc, char * * argv) +pwd_main(int argc, char * * argv) { char buf[1024]; if ( getcwd(buf, sizeof(buf)) == NULL ) { - name_and_error("get working directory"); - return 1; + perror("get working directory"); + exit( FALSE); } printf("%s\n", buf); - return 0; + exit( TRUE); } |