From d8cb881f04be06d0427a4956ff85311922cc5820 Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Mon, 29 May 2006 23:06:58 +0200 Subject: Write a many bytes as read --- inotail.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'inotail.c') diff --git a/inotail.c b/inotail.c index 3e326fa..bdabe9a 100644 --- a/inotail.c +++ b/inotail.c @@ -103,13 +103,13 @@ static off_t lines_to_offset(int fd, int file_size, unsigned int n_lines) static int tail_file(struct file_struct *f, int n_lines) { - int fd, rc; + int fd; + ssize_t rc = 0; off_t offset = 0; char buf[BUFFER_SIZE]; struct stat finfo; fd = open(f->name, O_RDONLY); - if (fd < 0) { perror("open()"); return -1; @@ -129,8 +129,10 @@ static int tail_file(struct file_struct *f, int n_lines) lseek(fd, offset, SEEK_SET); - while (read(fd, &buf, BUFFER_SIZE) != 0) { - rc = write(STDOUT_FILENO, buf, f->st_size - offset); + while ((rc = read(fd, &buf, BUFFER_SIZE)) != 0) { + dprintf(" f->st_size - offset: %lu\n", f->st_size - offset); + dprintf(" rc: %d\n", rc); + write(STDOUT_FILENO, buf, (size_t) rc); } close(fd); -- cgit v1.2.3-54-g00ecf