aboutsummaryrefslogtreecommitdiff
path: root/coreutils/tail.c
diff options
context:
space:
mode:
Diffstat (limited to 'coreutils/tail.c')
-rw-r--r--coreutils/tail.c22
1 files changed, 9 insertions, 13 deletions
diff --git a/coreutils/tail.c b/coreutils/tail.c
index 340697f88..52aa8f69e 100644
--- a/coreutils/tail.c
+++ b/coreutils/tail.c
@@ -101,16 +101,12 @@ int tail_main(int argc, char **argv)
101 101
102#if ENABLE_INCLUDE_SUSv2 || ENABLE_FEATURE_FANCY_TAIL 102#if ENABLE_INCLUDE_SUSv2 || ENABLE_FEATURE_FANCY_TAIL
103 /* Allow legacy syntax of an initial numeric option without -n. */ 103 /* Allow legacy syntax of an initial numeric option without -n. */
104 if (argc >= 2 && (argv[1][0] == '+' || argv[1][0] == '-') 104 if (argv[1] && (argv[1][0] == '+' || argv[1][0] == '-')
105 && isdigit(argv[1][1]) 105 && isdigit(argv[1][1])
106 ) { 106 ) {
107 /* replacing arg[0] with "-n" can segfault, so... */ 107 count = eat_num(&argv[1][1]);
108 argv[1] = xasprintf("-n%s", argv[1]); 108 argv++;
109#if 0 /* If we ever decide to make tail NOFORK */ 109 argc--;
110 char *s = alloca(strlen(argv[1]) + 3);
111 sprintf(s, "-n%s", argv[1]);
112 argv[1] = s;
113#endif
114 } 110 }
115#endif 111#endif
116 112
@@ -133,8 +129,7 @@ int tail_main(int argc, char **argv)
133 129
134 /* open all the files */ 130 /* open all the files */
135 fds = xmalloc(sizeof(int) * (argc + 1)); 131 fds = xmalloc(sizeof(int) * (argc + 1));
136 nfiles = i = 0; 132 if (!argv[0]) {
137 if (argc == 0) {
138 struct stat statbuf; 133 struct stat statbuf;
139 134
140 if (!fstat(STDIN_FILENO, &statbuf) && S_ISFIFO(statbuf.st_mode)) { 135 if (!fstat(STDIN_FILENO, &statbuf) && S_ISFIFO(statbuf.st_mode)) {
@@ -142,13 +137,14 @@ int tail_main(int argc, char **argv)
142 } 137 }
143 *argv = (char *) bb_msg_standard_input; 138 *argv = (char *) bb_msg_standard_input;
144 } 139 }
140 nfiles = i = 0;
145 do { 141 do {
146 FILE* fil = fopen_or_warn_stdin(argv[i]); 142 int fd = open_or_warn_stdin(argv[i]);
147 if (!fil) { 143 if (fd < 0) {
148 G.status = EXIT_FAILURE; 144 G.status = EXIT_FAILURE;
149 continue; 145 continue;
150 } 146 }
151 fds[nfiles] = fileno(fil); 147 fds[nfiles] = fd;
152 argv[nfiles++] = argv[i]; 148 argv[nfiles++] = argv[i];
153 } while (++i < argc); 149 } while (++i < argc);
154 150