mirror of
https://git.hardenedbsd.org/hardenedbsd/HardenedBSD.git
synced 2024-11-24 01:07:21 +01:00
The "cat - -" feature was broken by the last commit.
Restore the code that avoided closing and reopening stdin. This is also required by POSIX. As a bonus, enable multiple stdin reads with the -benstv flags, by resetting the EOF condition on stdin.
This commit is contained in:
parent
3418ebebfe
commit
1b00c916a1
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=83961
@ -135,13 +135,14 @@ scanfiles(argv, cooked)
|
||||
{
|
||||
int i = 0;
|
||||
char *path;
|
||||
FILE *fp;
|
||||
|
||||
while ((path = argv[i]) != NULL || i == 0) {
|
||||
int fd;
|
||||
|
||||
if (path == NULL || strcmp(path, "-") == 0) {
|
||||
filename = "stdin";
|
||||
fd = 0;
|
||||
fd = STDIN_FILENO;
|
||||
} else {
|
||||
filename = path;
|
||||
fd = open(path, O_RDONLY);
|
||||
@ -154,11 +155,16 @@ scanfiles(argv, cooked)
|
||||
warn("%s", path);
|
||||
rval = 1;
|
||||
} else if (cooked) {
|
||||
FILE *fp = fdopen(fd, "r");
|
||||
if (fd == STDIN_FILENO)
|
||||
cook_cat(stdin);
|
||||
else {
|
||||
fp = fdopen(fd, "r");
|
||||
cook_cat(fp);
|
||||
fclose(fp);
|
||||
}
|
||||
} else {
|
||||
raw_cat(fd);
|
||||
if (fd != STDIN_FILENO)
|
||||
close(fd);
|
||||
}
|
||||
if (path == NULL)
|
||||
@ -173,6 +179,10 @@ cook_cat(fp)
|
||||
{
|
||||
register int ch, gobble, line, prev;
|
||||
|
||||
/* Reset EOF condition on stdin. */
|
||||
if (fp == stdin && feof(stdin))
|
||||
clearerr(stdin);
|
||||
|
||||
line = gobble = 0;
|
||||
for (prev = '\n'; (ch = getc(fp)) != EOF; prev = ch) {
|
||||
if (prev == '\n') {
|
||||
|
Loading…
Reference in New Issue
Block a user