From 11c742e47c63f568782d9beee884c934ebbe143b Mon Sep 17 00:00:00 2001 From: Christos Zoulas Date: Fri, 3 Nov 2017 23:28:04 +0000 Subject: [PATCH] Add the end-of-file offset as a field. --- src/buffer.c | 6 ++++-- src/file.h | 3 ++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/buffer.c b/src/buffer.c index a72b8ce6..38f18c4e 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -27,7 +27,7 @@ #include "file.h" #ifndef lint -FILE_RCSID("@(#)$File: buffer.c,v 1.2 2017/11/03 00:18:55 christos Exp $") +FILE_RCSID("@(#)$File: buffer.c,v 1.3 2017/11/03 23:28:04 christos Exp $") #endif /* lint */ #include "magic.h" @@ -41,6 +41,7 @@ buffer_init(struct buffer *b, int fd, const void *data, size_t len) b->fd = fd; b->fbuf = data; b->flen = len; + b->eoff = 0; b->ebuf = NULL; b->elen = 0; } @@ -68,7 +69,8 @@ buffer_fill(const struct buffer *bb) if ((b->ebuf = malloc(b->elen)) == NULL) goto out; - if (pread(b->fd, b->ebuf, b->elen, st.st_size - b->elen) == -1) { + b->eoff = st.st_size - b->elen; + if (pread(b->fd, b->ebuf, b->elen, b->eoff) == -1) { free(b->ebuf); goto out; } diff --git a/src/file.h b/src/file.h index 133c0e88..58cfc2f3 100644 --- a/src/file.h +++ b/src/file.h @@ -27,7 +27,7 @@ */ /* * file.h - definitions for file(1) program - * @(#)$File: file.h,v 1.189 2017/11/03 14:28:54 christos Exp $ + * @(#)$File: file.h,v 1.190 2017/11/03 23:28:04 christos Exp $ */ #ifndef __file_h__ @@ -149,6 +149,7 @@ struct buffer { int fd; const void *fbuf; size_t flen; + off_t eoff; void *ebuf; size_t elen; }; -- 2.40.0