}
/* For the file FILENAME with descriptor FD, output all but the last N_ELIDE
- bytes. If SIZE is nonnegative, this is a regular file positioned
- at CURRENT_POS with SIZE bytes. Return true on success.
+ bytes. If CURRENT_POS is nonnegative, this is a regular file positioned
+ at CURRENT_POS. The file's status is ST. Return true on success.
Give a diagnostic and return false upon error. */
/* NOTE: if the input file shrinks by more than N_ELIDE bytes between
struct stat const *st, off_t current_pos)
{
off_t size = st->st_size;
- if (presume_input_pipe || current_pos < 0 || size <= STP_BLKSIZE (st))
+ if (current_pos < 0 || size <= STP_BLKSIZE (st))
return elide_tail_bytes_pipe (filename, fd, n_elide, current_pos);
else
{
}
/* For the file FILENAME with descriptor FD, output all but the last N_ELIDE
- lines. If SIZE is nonnegative, this is a regular file positioned
- at START_POS with SIZE bytes. Return true on success.
- Give a diagnostic and return nonzero upon error. */
+ lines. If CURRENT_POS is nonnegative, this is a regular file positioned
+ at CURRENT_POS. The file's status is ST. Return true on success.
+ Give a diagnostic and return false upon error. */
static bool
elide_tail_lines_file (char const *filename, int fd, uintmax_t n_elide,
struct stat const *st, off_t current_pos)
{
off_t size = st->st_size;
- if (presume_input_pipe || current_pos < 0 || size <= STP_BLKSIZE (st))
+ if (current_pos < 0 || size <= STP_BLKSIZE (st))
return elide_tail_lines_pipe (filename, fd, n_elide, current_pos);
else
{
quoteaf (filename));
return false;
}
- if (! presume_input_pipe && usable_st_size (&st))
+ if (! presume_input_pipe && S_ISREG (st.st_mode))
{
current_pos = elseek (fd, 0, SEEK_CUR, filename);
if (current_pos < 0)
if (fstat (fileno (in_stream), &file_stats) == 0)
{
- bool usable_size = usable_st_size (&file_stats);
-
/* The st_size field is valid for regular files.
If the number of bytes left to skip is larger than
the size of the current file, we can decrement n_skip
when st_size is no greater than the block size, because
some kernels report nonsense small file sizes for
proc-like file systems. */
- if (usable_size && STP_BLKSIZE (&file_stats) < file_stats.st_size)
+ if (S_ISREG (file_stats.st_mode)
+ && STP_BLKSIZE (&file_stats) < file_stats.st_size)
{
if (file_stats.st_size < n_skip)
n_skip -= file_stats.st_size;
}
}
- else if (!usable_size && fseeko (in_stream, n_skip, SEEK_CUR) == 0)
+ else if (! (S_ISREG (file_stats.st_mode)
+ || S_TYPEISSHM (&file_stats)
+ || S_TYPEISTMO (&file_stats))
+ && fseeko (in_stream, n_skip, SEEK_CUR) == 0)
n_skip = 0;
- /* If it's not a regular file with nonnegative size,
- or if it's so small that it might be in a proc-like file system,
+ /* If it's neither a seekable file with unusable size, nor a
+ regular file so large it can't be in a proc-like file system,
position the file pointer by reading. */
else