summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTobias Klauser <tklauser@xenon.tklauser.home>2006-05-29 23:06:58 +0200
committerTobias Klauser <tklauser@xenon.tklauser.home>2006-05-29 23:06:58 +0200
commitd8cb881f04be06d0427a4956ff85311922cc5820 (patch)
tree23a51b29f0d16412c1161afeb7d590d95b34b2dd
parente4c53b4c40972a78ecbff9773b9f5da2a86b528e (diff)
Write a many bytes as read
-rw-r--r--inotail.c10
1 files changed, 6 insertions, 4 deletions
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);