diff options
-rw-r--r-- | miscutils/less.c | 16 |
1 files changed, 5 insertions, 11 deletions
diff --git a/miscutils/less.c b/miscutils/less.c index be8d20e66..7a441bf7e 100644 --- a/miscutils/less.c +++ b/miscutils/less.c | |||
@@ -615,11 +615,12 @@ static int safe_lineno(int fline) | |||
615 | static void update_num_lines(void) | 615 | static void update_num_lines(void) |
616 | { | 616 | { |
617 | int count, fd; | 617 | int count, fd; |
618 | struct stat stbuf; | ||
618 | ssize_t len, i; | 619 | ssize_t len, i; |
619 | char buf[4096]; | 620 | char buf[4096]; |
620 | 621 | ||
621 | /* only do this for regular files */ | 622 | /* only do this for regular files */ |
622 | if (num_lines != NOT_REGULAR_FILE) { | 623 | if (num_lines == REOPEN_AND_COUNT || num_lines == REOPEN_STDIN) { |
623 | count = 0; | 624 | count = 0; |
624 | fd = open("/proc/self/fd/0", O_RDONLY); | 625 | fd = open("/proc/self/fd/0", O_RDONLY); |
625 | if (fd < 0 && num_lines == REOPEN_AND_COUNT) { | 626 | if (fd < 0 && num_lines == REOPEN_AND_COUNT) { |
@@ -631,17 +632,10 @@ static void update_num_lines(void) | |||
631 | num_lines = NOT_REGULAR_FILE; | 632 | num_lines = NOT_REGULAR_FILE; |
632 | return; | 633 | return; |
633 | } | 634 | } |
634 | #if ENABLE_FEATURE_LESS_FLAGS | 635 | if (fstat(fd, &stbuf) != 0 || !S_ISREG(stbuf.st_mode)) { |
635 | { | 636 | num_lines = NOT_REGULAR_FILE; |
636 | struct stat stbuf; | 637 | goto do_close; |
637 | if (fstat(fd, &stbuf) != 0 | ||
638 | || !S_ISREG(stbuf.st_mode) | ||
639 | ) { | ||
640 | num_lines = NOT_REGULAR_FILE; | ||
641 | goto do_close; | ||
642 | } | ||
643 | } | 638 | } |
644 | #endif | ||
645 | while ((len = safe_read(fd, buf, sizeof(buf))) > 0) { | 639 | while ((len = safe_read(fd, buf, sizeof(buf))) > 0) { |
646 | for (i = 0; i < len; ++i) { | 640 | for (i = 0; i < len; ++i) { |
647 | if (buf[i] == '\n' && ++count == MAXLINES) | 641 | if (buf[i] == '\n' && ++count == MAXLINES) |