From fd58837bf186c49a681f0c498cbaa17a87b69408 Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Tue, 9 May 2006 16:38:30 +0200 Subject: Check for block_size bigger than BUFFER_SIZE in watch_file --- simpletail.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/simpletail.c b/simpletail.c index 196dfe2..fa47668 100644 --- a/simpletail.c +++ b/simpletail.c @@ -141,13 +141,20 @@ static int watch_file(const char *filename, off_t offset) return -1; } - /* XXX: block_size could be bigger than BUFFER_SIZE */ block_size = finfo.st_size - offset; + if (block_size < 0) block_size = 0; + /* XXX: Dirty hack for now to make sure + * block_size doesn't get bigger than + * BUFFER_SIZE + */ + if (block_size > BUFFER_SIZE) + block_size = BUFFER_SIZE; + lseek(ffd, offset, SEEK_SET); - while (read(ffd, &fbuf, BUFFER_SIZE) != 0) { + while (read(ffd, &fbuf, block_size) != 0) { write(STDOUT_FILENO, fbuf, block_size); } -- cgit v1.2.3-54-g00ecf