From 30ca6838a2898d0482df790249f3d53f8f5e553c Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Fri, 8 Jun 2007 15:19:48 +0200 Subject: inotail.c: Prepare for implementation of tail_pipe_{lines,bytes} Split in two functions --- inotail.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/inotail.c b/inotail.c index bb27702..0b77deb 100644 --- a/inotail.c +++ b/inotail.c @@ -218,15 +218,11 @@ static off_t bytes_to_offset(struct file_struct *f, unsigned long n_bytes) return offset; } -static ssize_t tail_pipe(struct file_struct *f) +static ssize_t tail_pipe_lines(struct file_struct *f, unsigned long n_lines) { ssize_t rc; char buf[BUFFER_SIZE]; - if (verbose) - write_header(f->name); - - /* FIXME: We will just tail everything here for now */ while ((rc = read(f->fd, buf, BUFFER_SIZE)) > 0) { if (write(STDOUT_FILENO, buf, (size_t) rc) <= 0) { /* e.g. when writing to a pipe which gets closed */ @@ -238,6 +234,11 @@ static ssize_t tail_pipe(struct file_struct *f) return rc; } +static ssize_t tail_pipe_bytes(struct file_struct *f, unsigned long n_bytes) { + /* TODO: Implement me :) */ + return 0; +} + static int tail_file(struct file_struct *f, unsigned long n_units, char mode, char forever) { ssize_t bytes_read = 0; @@ -269,8 +270,15 @@ static int tail_file(struct file_struct *f, unsigned long n_units, char mode, ch } /* Cannot seek on these */ - if (IS_PIPELIKE(finfo.st_mode) || f->fd == STDIN_FILENO) - return tail_pipe(f); + if (IS_PIPELIKE(finfo.st_mode) || f->fd == STDIN_FILENO) { + if (verbose) + write_header(f->name); + + if (mode == M_LINES) + return tail_pipe_lines(f, n_units); + else + return tail_pipe_bytes(f, n_units); + } f->st_size = finfo.st_size; -- cgit v1.2.3-54-g00ecf