From 91a7b57fa4e2d633563192d5c2b47f6042d2ea49 Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Sat, 20 Jan 2007 18:37:18 +0100 Subject: inotail.c: Adjust block size according to return value of read ...and use proper types --- inotail.c | 7 ++++--- 1 file 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') { -- cgit v1.2.3-54-g00ecf