valid_file_spec (struct File_spec const *f)
{
/* Exactly one of the following subexpressions must be true. */
- return ((f->fd == -1) ^ (f->errnum == 0));
+ return (f->fd < 0) ^ (f->errnum == 0);
}
/* Call lseek with the specified arguments FD, OFFSET, WHENCE.
/* If the open fails because the file doesn't exist,
then mark the file as not tailable. */
- f->tailable = !(reopen_inaccessible_files && fd == -1);
+ f->tailable = !(reopen_inaccessible_files && fd < 0);
if (! disable_inotify && ! lstat (f->name, &new_stats)
&& S_ISLNK (new_stats.st_mode))
error (0, 0, _("%s has been replaced with an untailable symbolic link"),
quoteaf (f->prettyname));
}
- else if (fd == -1 || fstat (fd, &new_stats) < 0)
+ else if (fd < 0 || fstat (fd, &new_stats) < 0)
{
ok = false;
f->errnum = errno;
else if (prev_errnum && prev_errnum != ENOENT)
{
new_file = true;
- affirm (f->fd == -1);
+ affirm (f->fd < 0);
error (0, 0, _("%s has become accessible"), quoteaf (f->prettyname));
}
- else if (f->fd == -1)
+ else if (f->fd < 0)
{
/* A new file even when inodes haven't changed as <dev,inode>
pairs can be reused, and we know the file was missing
for (int i = 0; i < nbpids; i++)
{
- if (kill (pids[i], 0) == 0 || errno == EPERM)
+ if (! (kill (pids[i], 0) < 0 && errno != EPERM))
return false;
}
{
/* Use blocking I/O as an optimization, when it's easy. */
bool blocking = (!nbpids && follow_mode == Follow_descriptor
- && n_files == 1 && f[0].fd != -1 && ! S_ISREG (f[0].mode));
+ && n_files == 1 && 0 <= f[0].fd && ! S_ISREG (f[0].mode));
bool writers_dead = false;
int last = n_files - 1;
int new_flags = old_flags | (blocking ? 0 : O_NONBLOCK);
if (old_flags < 0
|| (new_flags != old_flags
- && fcntl (fd, F_SETFL, new_flags) == -1))
+ && fcntl (fd, F_SETFL, new_flags) < 0))
{
/* Don't update f[i].blocking if fcntl fails. */
if (S_ISREG (f[i].mode) && errno == EPERM)
bool read_unchanged = false;
if (!f[i].blocking)
{
- if (fstat (fd, &stats) != 0)
+ if (fstat (fd, &stats) < 0)
{
f[i].fd = -1;
f[i].errnum = errno;
break;
}
- if ((!any_input || blocking) && fflush (stdout) != 0)
+ if ((!any_input || blocking) && fflush (stdout) < 0)
write_error ();
check_output_alive ();
return;
struct stat stats;
- if (fstat (fspec->fd, &stats) != 0)
+ if (fstat (fspec->fd, &stats) < 0)
{
fspec->errnum = errno;
close_fd (fspec->fd, fspec);
if (S_ISREG (fspec->mode))
fspec->read_pos += nr;
*prev_fspec = fspec;
- if (fflush (stdout) != 0)
+ if (fflush (stdout) < 0)
write_error ();
}
}
if (f[i].wd < 0)
{
- if (f[i].fd != -1) /* already tailed. */
+ if (0 <= f[i].fd) /* already tailed. */
tailed_but_unwatchable = true;
if (errno == ENOSPC || errno == ENOMEM)
{
/* check for new files. */
if (follow_mode == Follow_name)
recheck (&(f[i]), false);
- else if (f[i].fd != -1)
+ else if (0 <= f[i].fd)
{
/* If the file was replaced in the small window since we tailed,
then assume the watch is on the wrong item (different to
polling the original descriptor. */
struct stat stats;
- if (stat (f[i].name, &stats) == 0
- && (f[i].dev != stats.st_dev || f[i].ino != stats.st_ino))
+ if (! (stat (f[i].name, &stats) < 0
+ || (f[i].dev == stats.st_dev && f[i].ino == stats.st_ino)))
{
error (0, errno, _("%s was replaced"),
quoteaf (f[i].prettyname));
fspec->wd = new_wd;
- if (new_wd == -1)
+ if (new_wd < 0)
continue;
/* If the file was moved then inotify will use the source file wd
else
fd = open (f->name, O_RDONLY | O_BINARY | (nonblocking ? O_NONBLOCK : 0));
- f->tailable = !(reopen_inaccessible_files && fd == -1);
+ f->tailable = !(reopen_inaccessible_files && fd < 0);
- if (fd == -1)
+ if (fd < 0)
{
if (forever)
{
}
else
{
- if (!is_stdin && close (fd))
+ if (!is_stdin && close (fd) < 0)
{
error (0, errno, _("error reading %s"),
quoteaf (f->prettyname));
if (nbpids && !forever)
error (0, 0,
_("warning: PID ignored; --pid=PID is useful only when following"));
- else if (nbpids && kill (pids[0], 0) != 0 && errno == ENOSYS)
+ else if (nbpids && kill (pids[0], 0) < 0 && errno == ENOSYS)
{
error (0, 0, _("warning: --pid=PID is not supported on this system"));
nbpids = 0;
/* Flush any output from tail_file, now, since
tail_forever_inotify flushes only after writing,
not before reading. */
- if (fflush (stdout) != 0)
+ if (fflush (stdout) < 0)
write_error ();
Hash_table *ht;