aboutsummaryrefslogtreecommitdiff
path: root/coreutils
diff options
context:
space:
mode:
Diffstat (limited to 'coreutils')
-rw-r--r--coreutils/head.c7
-rw-r--r--coreutils/tail.c5
2 files changed, 11 insertions, 1 deletions
diff --git a/coreutils/head.c b/coreutils/head.c
index 4a1677146..c5c11fc7b 100644
--- a/coreutils/head.c
+++ b/coreutils/head.c
@@ -47,12 +47,17 @@ int head_main(int argc, char **argv)
FILE *fp;
int need_headers, opt, len = 10, status = EXIT_SUCCESS;
+ if (( argc >= 2 ) && ( strlen ( argv [1] ) >= 2 ) && ( argv [1][0] == '-' ) && isdigit ( argv [1][1] )) {
+ len = atoi ( &argv [1][1] );
+ optind = 2;
+ }
+
/* parse argv[] */
while ((opt = getopt(argc, argv, "n:")) > 0) {
switch (opt) {
case 'n':
len = atoi(optarg);
- if (len >= 1)
+ if (len >= 0)
break;
/* fallthrough */
default:
diff --git a/coreutils/tail.c b/coreutils/tail.c
index 0c8dec26a..8201c80a0 100644
--- a/coreutils/tail.c
+++ b/coreutils/tail.c
@@ -68,6 +68,11 @@ int tail_main(int argc, char **argv)
char *s, *start, *end, buf[BUFSIZ];
int i, opt;
+ if (( argc >= 2 ) && ( strlen ( argv [1] ) >= 2 ) && ( argv [1][0] == '-' ) && isdigit ( argv [1][1] )) {
+ count = atoi ( &argv [1][1] );
+ optind = 2;
+ }
+
while ((opt = getopt(argc, argv, "c:fhn:q:s:v")) > 0) {
switch (opt) {
case 'f':