summaryrefslogtreecommitdiff
path: root/inotail.c
diff options
context:
space:
mode:
authorTobias Klauser <tklauser@distanz.ch>2007-06-20 10:59:39 +0200
committerTobias Klauser <tklauser@xenon.tklauser.home>2007-06-20 10:59:39 +0200
commit19699a5c202019e98c612eb1db28adb7588f78bd (patch)
treea58e53d110feb4897f62cbddf3f5a64da6d9ea8d /inotail.c
parentb9848ce99f13bdf07ab5e538422d83280a6fe321 (diff)
inotail.c: Move allocation of buffer before place where buf is used
This saves two possible free calls
Diffstat (limited to 'inotail.c')
-rw-r--r--inotail.c6
1 files changed, 2 insertions, 4 deletions
diff --git a/inotail.c b/inotail.c
index 5917d4a..9000f46 100644
--- a/inotail.c
+++ b/inotail.c
@@ -297,8 +297,6 @@ static int tail_file(struct file_struct *f, unsigned long n_units, char mode, ch
f->st_size = finfo.st_size;
f->st_blksize = finfo.st_blksize; /* TODO: Can this value be 0 or negative? */
- buf = emalloc(f->st_blksize);
-
if (mode == M_LINES)
offset = lines_to_offset(f, n_units);
else
@@ -307,7 +305,6 @@ static int tail_file(struct file_struct *f, unsigned long n_units, char mode, ch
/* We only get negative offsets on errors */
if (unlikely(offset < 0)) {
ignore_file(f);
- free(buf);
return -1;
}
@@ -316,10 +313,11 @@ static int tail_file(struct file_struct *f, unsigned long n_units, char mode, ch
if (lseek(f->fd, offset, SEEK_SET) == (off_t) -1) {
fprintf(stderr, "Error: Could not seek in file '%s' (%s)\n", f->name, strerror(errno));
- free(buf);
return -1;
}
+ buf = emalloc(f->st_blksize);
+
while ((bytes_read = read(f->fd, buf, f->st_blksize)) > 0)
write(STDOUT_FILENO, buf, (size_t) bytes_read);