summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTobias Klauser <tklauser@distanz.ch>2007-01-20 18:37:18 +0100
committerTobias Klauser <tklauser@xenon.tklauser.home>2007-01-20 18:37:18 +0100
commit91a7b57fa4e2d633563192d5c2b47f6042d2ea49 (patch)
treee60e13ac560d77dd4d116578d578e71cc2a124c0
parente7d1bd52c77ed84676514dc09ac7087262d53e9b (diff)
inotail.c: Adjust block size according to return value of read
...and use proper types
-rw-r--r--inotail.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/inotail.c b/inotail.c
index 724c471..8695855 100644
--- a/inotail.c
+++ b/inotail.c
@@ -157,8 +157,8 @@ static off_t lines_to_offset_from_begin(struct file_struct *f, unsigned int n_li
memset(&buf, 0, sizeof(buf));
while (offset <= f->st_size && n_lines > 0) {
- int i, rc;
- int block_size = BUFFER_SIZE;
+ int i;
+ ssize_t rc, block_size = BUFFER_SIZE;
lseek(f->fd, offset, SEEK_SET);
@@ -166,7 +166,8 @@ static off_t lines_to_offset_from_begin(struct file_struct *f, unsigned int n_li
if (rc < 0) {
fprintf(stderr, "Error: Could not read from file '%s' (%s)\n", f->name, strerror(errno));
return -1;
- }
+ } else if (rc < block_size)
+ block_size = rc;
for (i = 0; i < block_size; i++) {
if (buf[i] == '\n') {