summaryrefslogtreecommitdiff
path: root/inotail.c
diff options
context:
space:
mode:
authorTobias Klauser <tklauser@distanz.ch>2007-06-08 15:19:48 +0200
committerTobias Klauser <tklauser@xenon.tklauser.home>2007-06-08 15:19:48 +0200
commit30ca6838a2898d0482df790249f3d53f8f5e553c (patch)
treef83b58192e92ceb8834b10b0298f641602ddd8d2 /inotail.c
parent01f54bb5e9a1d6373a508859dcc809f5cdb5cd64 (diff)
inotail.c: Prepare for implementation of tail_pipe_{lines,bytes}
Split in two functions
Diffstat (limited to 'inotail.c')
-rw-r--r--inotail.c22
1 files 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;