From 19699a5c202019e98c612eb1db28adb7588f78bd Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Wed, 20 Jun 2007 10:59:39 +0200 Subject: inotail.c: Move allocation of buffer before place where buf is used This saves two possible free calls --- inotail.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'inotail.c') 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); -- cgit v1.2.3-54-g00ecf