{ NULL, 0 }
};
-static int status;
+struct globals {
+ bool status;
+};
+#define G (*(struct globals*)&bb_common_bufsiz1)
static void tail_xprint_header(const char *fmt, const char *filename)
{
r = safe_read(fd, buf, count);
if (r < 0) {
bb_perror_msg(bb_msg_read_error);
- status = EXIT_FAILURE;
+ G.status = EXIT_FAILURE;
}
return r;
static unsigned eat_num(const char *p) {
if (*p == '-') p++;
- else if (*p == '+') { p++; status = 1; }
+ else if (*p == '+') { p++; G.status = EXIT_FAILURE; }
return xatou_sfx(p, tail_suffixes);
}
#endif
argc -= optind;
argv += optind;
- from_top = status;
+ from_top = G.status;
/* open all the files */
fds = xmalloc(sizeof(int) * (argc + 1));
- status = nfiles = i = 0;
+ nfiles = i = 0;
+ G.status = EXIT_SUCCESS;
if (argc == 0) {
struct stat statbuf;
opt &= ~1; /* clear FOLLOW */
}
*argv = (char *) bb_msg_standard_input;
- goto DO_STDIN;
}
-
do {
- if (NOT_LONE_DASH(argv[i])) {
- fds[nfiles] = open(argv[i], O_RDONLY);
- if (fds[nfiles] < 0) {
- bb_perror_msg("%s", argv[i]);
- status = EXIT_FAILURE;
- continue;
- }
- } else {
- DO_STDIN: /* "-" */
- fds[nfiles] = STDIN_FILENO;
+ FILE* fil = fopen_or_warn_stdin(argv[i]);
+ if (!fil) {
+ G.status = EXIT_FAILURE;
+ continue;
}
- argv[nfiles] = argv[i];
- ++nfiles;
+ fds[nfiles] = fileno(fil);
+ argv[nfiles++] = argv[i];
} while (++i < argc);
if (!nfiles)
if (newline + nbuf < count) {
newline += nbuf;
taillen += nread;
-
} else {
int extra = 0;
- if (buf[nread-1] != '\n') {
- extra = 1;
- }
+ if (buf[nread-1] != '\n')
+ extra = 1;
k = newline + nbuf + extra - count;
s = tailbuf;
while (k) {
}
++s;
}
-
taillen += nread - (s - tailbuf);
memmove(tailbuf, s, taillen);
newline = count - extra;
}
} while (++i < nfiles);
}
-
- return status;
+ if (ENABLE_FEATURE_CLEAN_UP) {
+ free(fds);
+ }
+ return G.status;
}