summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTobias Klauser <tklauser@distanz.ch>2007-09-19 10:13:44 +0200
committerTobias Klauser <tklauser@xenon.tklauser.home>2007-09-19 10:13:44 +0200
commit6ec61a62e5a1a586766d46108d5ae7e1aaf3dd8c (patch)
treeec7dcec92fcee2bce373ce5bcc5c4be3704c3b4a
parentf4c22bb16fc842f66060d4f7a79338c900f8dfb9 (diff)
inotail.c: Check for n_units == 0 only if tailing from end
inotail -n+0/-c+0 should be allowed
-rw-r--r--inotail.c13
1 files 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