From 6ec61a62e5a1a586766d46108d5ae7e1aaf3dd8c Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Wed, 19 Sep 2007 10:13:44 +0200 Subject: inotail.c: Check for n_units == 0 only if tailing from end inotail -n+0/-c+0 should be allowed --- inotail.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/inotail.c b/inotail.c index 7ed5b31..483306e 100644 --- a/inotail.c +++ b/inotail.c @@ -244,7 +244,8 @@ static int tail_pipe_from_begin(struct file_struct *f, unsigned long n_units, co int bytes_read = 0; char buf[BUFSIZ]; - n_units--; + if (n_units) + n_units--; while (n_units > 0) { if ((bytes_read = read(f->fd, buf, BUFSIZ)) <= 0) { @@ -296,6 +297,9 @@ static int tail_pipe_lines(struct file_struct *f, unsigned long n_lines) if (from_begin) return tail_pipe_from_begin(f, n_lines, M_LINES); + if (n_lines == 0) + return 0; + first = last = emalloc(sizeof(struct line_buf)); first->n_bytes = first->n_lines = 0; first->next = NULL; @@ -401,6 +405,10 @@ static int tail_pipe_bytes(struct file_struct *f, unsigned long n_bytes) if (from_begin) return tail_pipe_from_begin(f, n_bytes, M_BYTES); + /* XXX: Needed? */ + if (n_bytes == 0) + return 0; + first = last = emalloc(sizeof(struct char_buf)); first->n_bytes = 0; first->next = NULL; @@ -507,9 +515,6 @@ static int tail_file(struct file_struct *f, unsigned long n_units, char mode, ch if (verbose) write_header(f->name); - if (n_units == 0) - return 0; - if (mode == M_LINES) return tail_pipe_lines(f, n_units); else -- cgit v1.2.3-54-g00ecf