diff options
author | Tobias Klauser <tklauser@distanz.ch> | 2007-04-16 11:04:49 +0200 |
---|---|---|
committer | Tobias Klauser <tklauser@xenon.tklauser.home> | 2007-04-16 11:04:49 +0200 |
commit | b65101beb4db64847d9bd2b770fe55521b97c8ed (patch) | |
tree | 4e37b96dbf4920f335f46c050891bddd0b712cee | |
parent | d7a9bccc00f2bc34dacd216ffd1a9bfa3bfa39fa (diff) |
inotail.c: Really fix byte_to_offset() this time
Also make a bit more readable
-rw-r--r-- | inotail.c | 18 |
1 files changed, 12 insertions, 6 deletions
@@ -198,12 +198,18 @@ static off_t lines_to_offset(struct file_struct *f, unsigned long n_lines) static off_t bytes_to_offset(struct file_struct *f, unsigned long n_bytes) { - /* tail everything for 'inotail -c +0' or if n_bytes greater than the - * total amount of chars in the file */ - if ((from_begin && n_bytes == 0) || ((off_t) n_bytes > f->st_size)) - return 0; - else - return (from_begin ? ((off_t) n_bytes - 1) : (f->st_size - (off_t) n_bytes)); + off_t offset = 0; + + /* tail everything for 'inotail -c +0' */ + if (from_begin) { + if (n_bytes > 0) + offset = (off_t) n_bytes - 1; + } else { + if ((off_t) n_bytes < f->st_size) + offset = f->st_size - (off_t) n_bytes; + } + + return offset; } static ssize_t tail_pipe(struct file_struct *f) |