summaryrefslogtreecommitdiff
path: root/inotail.c
diff options
context:
space:
mode:
Diffstat (limited to 'inotail.c')
-rw-r--r--inotail.c11
1 files changed, 4 insertions, 7 deletions
diff --git a/inotail.c b/inotail.c
index e9238a1..0a519d3 100644
--- a/inotail.c
+++ b/inotail.c
@@ -123,8 +123,7 @@ static off_t lines_to_offset_from_end(struct file_struct *f, unsigned int n_line
for (i = block_size; i > 0; i--) {
if (buf[i] == '\n') {
- n_lines--;
- if (n_lines == 0)
+ if (--n_lines == 0)
return offset += i + 1; /* We don't want the first \n */
}
}
@@ -160,8 +159,7 @@ static off_t lines_to_offset_from_begin(struct file_struct *f, unsigned int n_li
for (i = 0; i < block_size; i++) {
if (buf[i] == '\n') {
- n_lines--;
- if (n_lines == 0)
+ if (--n_lines == 0)
return offset + i + 1;
}
}
@@ -287,12 +285,11 @@ static int handle_inotify_event(struct inotify_event *inev, struct file_struct *
offset = fil->st_size;
fil->st_size = finfo.st_size;
+ memset(&fbuf, 0, sizeof(fbuf));
if (verbose)
write_header(fil->name);
- memset(&fbuf, 0, sizeof(fbuf));
-
lseek(fil->fd, offset, SEEK_SET);
while ((rc = read(fil->fd, &fbuf, BUFFER_SIZE)) != 0)
write(STDOUT_FILENO, fbuf, rc);
@@ -432,7 +429,7 @@ int main(int argc, char **argv)
}
files = malloc(n_files * sizeof(struct file_struct));
- if (!files) {
+ if (unlikely(!files)) {
fprintf(stderr, "Error: Not enough memory (%s)\n", strerror(errno));
exit(EXIT_FAILURE);
}