summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTobias Klauser <tklauser@distanz.ch>2006-12-18 12:53:37 +0100
committerTobias Klauser <tklauser@sym.(none)>2006-12-18 12:53:37 +0100
commit06be3975d174002702121481310b28a894284339 (patch)
treec87fc53e369473bade77e1bee4e7549616f48889
parentf1d16fb3b3e44054262e4d5d07bee23ebc215aed (diff)
inotail.c: Minor cleanups and addition of an unlikely()
-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);
}