PR/57850: Ricardo Branco: tail does not work in some pseudo-filesystems

From FreeBSD: https://github.com/NetBSD/src/pull/20
This commit is contained in:
christos 2024-01-14 17:37:32 +00:00
parent f4066449c8
commit e39dc43f61
1 changed files with 5 additions and 5 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: forward.c,v 1.33 2015/10/09 17:51:26 christos Exp $ */
/* $NetBSD: forward.c,v 1.34 2024/01/14 17:37:32 christos Exp $ */
/*-
* Copyright (c) 1991, 1993
@ -37,7 +37,7 @@
#if 0
static char sccsid[] = "@(#)forward.c 8.1 (Berkeley) 6/6/93";
#endif
__RCSID("$NetBSD: forward.c,v 1.33 2015/10/09 17:51:26 christos Exp $");
__RCSID("$NetBSD: forward.c,v 1.34 2024/01/14 17:37:32 christos Exp $");
#endif /* not lint */
#include <sys/types.h>
@ -96,7 +96,7 @@ forward(FILE *fp, enum STYLE style, off_t off, struct stat *sbp)
case FBYTES:
if (off == 0)
break;
if (S_ISREG(sbp->st_mode)) {
if (S_ISREG(sbp->st_mode) && sbp->st_size > 0) {
if (sbp->st_size < off)
off = sbp->st_size;
if (fseeko(fp, off, SEEK_SET) == -1) {
@ -128,7 +128,7 @@ forward(FILE *fp, enum STYLE style, off_t off, struct stat *sbp)
}
break;
case RBYTES:
if (S_ISREG(sbp->st_mode)) {
if (S_ISREG(sbp->st_mode) && sbp->st_size > 0) {
if (sbp->st_size >= off &&
fseeko(fp, -off, SEEK_END) == -1) {
ierr();
@ -146,7 +146,7 @@ forward(FILE *fp, enum STYLE style, off_t off, struct stat *sbp)
}
break;
case RLINES:
if (S_ISREG(sbp->st_mode)) {
if (S_ISREG(sbp->st_mode) && sbp->st_size > 0) {
if (!off) {
if (fseek(fp, 0L, SEEK_END) == -1) {
ierr();