summaryrefslogtreecommitdiff
path: root/coreutils/tail.c
diff options
context:
space:
mode:
authorMatt Kraai2000-12-18 21:38:57 +0000
committerMatt Kraai2000-12-18 21:38:57 +0000
commit24ac0179617e43ab517141fe5497f4ebac108678 (patch)
tree333d1ef43d092edd4b41030112cb71559bf9cb3a /coreutils/tail.c
parent0d2acb0eadf2d6ae9d60fa3fe9f897e254eaadda (diff)
downloadbusybox-24ac0179617e43ab517141fe5497f4ebac108678.zip
busybox-24ac0179617e43ab517141fe5497f4ebac108678.tar.gz
Rewrote dd.
Diffstat (limited to 'coreutils/tail.c')
-rw-r--r--coreutils/tail.c48
1 files changed, 14 insertions, 34 deletions
diff --git a/coreutils/tail.c b/coreutils/tail.c
index 308bb30..5f03818 100644
--- a/coreutils/tail.c
+++ b/coreutils/tail.c
@@ -61,6 +61,13 @@ static char verbose = 0;
static off_t units=0;
+static struct suffix_mult tail_suffixes[] = {
+ { "b", 512 },
+ { "k", 1024 },
+ { "m", 1048576 },
+ { NULL, 0 }
+};
+
static int tail_stream(int fd)
{
ssize_t startpoint;
@@ -170,32 +177,6 @@ int tail_main(int argc, char **argv)
switch (opt) {
#ifndef BB_FEATURE_SIMPLE_TAIL
- case 'c':
- unit_type = BYTES;
- test = atoi(optarg);
- if(test==0)
- usage(tail_usage);
- if(optarg[strlen(optarg)-1]>'9') {
- switch (optarg[strlen(optarg)-1]) {
- case 'b':
- test *= 512;
- break;
- case 'k':
- test *= 1024;
- break;
- case 'm':
- test *= (1024 * 1024);
- break;
- default:
- fprintf(stderr,"Size must be b,k, or m.");
- usage(tail_usage);
- }
- }
- if(optarg[0]=='+')
- units=test+1;
- else
- units=-(test+1);
- break;
case 'q':
show_headers = 0;
break;
@@ -207,15 +188,12 @@ int tail_main(int argc, char **argv)
case 'v':
verbose = 1;
break;
+ case 'c':
+ unit_type = BYTES;
+ /* FALLS THROUGH */
#endif
- case 'f':
- follow = 1;
- break;
- case 'h':
- usage(tail_usage);
- break;
case 'n':
- test = atoi(optarg);
+ test = parse_number(optarg, tail_suffixes);
if (test) {
if (optarg[0] == '+')
units = test;
@@ -224,8 +202,10 @@ int tail_main(int argc, char **argv)
} else
usage(tail_usage);
break;
+ case 'f':
+ follow = 1;
+ break;
default:
- error_msg("\nUnknown arg: %c.\n\n",optopt);
usage(tail_usage);
}
}