diff options
author | Tobias Klauser <tklauser@distanz.ch> | 2007-06-08 15:19:48 +0200 |
---|---|---|
committer | Tobias Klauser <tklauser@xenon.tklauser.home> | 2007-06-08 15:19:48 +0200 |
commit | 30ca6838a2898d0482df790249f3d53f8f5e553c (patch) | |
tree | f83b58192e92ceb8834b10b0298f641602ddd8d2 | |
parent | 01f54bb5e9a1d6373a508859dcc809f5cdb5cd64 (diff) |
inotail.c: Prepare for implementation of tail_pipe_{lines,bytes}
Split in two functions
-rw-r--r-- | inotail.c | 22 |
1 files changed, 15 insertions, 7 deletions
@@ -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; |