diff options
author | Tobias Klauser <tklauser@distanz.ch> | 2007-06-20 10:59:39 +0200 |
---|---|---|
committer | Tobias Klauser <tklauser@xenon.tklauser.home> | 2007-06-20 10:59:39 +0200 |
commit | 19699a5c202019e98c612eb1db28adb7588f78bd (patch) | |
tree | a58e53d110feb4897f62cbddf3f5a64da6d9ea8d | |
parent | b9848ce99f13bdf07ab5e538422d83280a6fe321 (diff) |
inotail.c: Move allocation of buffer before place where buf is used
This saves two possible free calls
-rw-r--r-- | inotail.c | 6 |
1 files changed, 2 insertions, 4 deletions
@@ -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); |