commit 0f8ae18c98101a92b0608c6b719bb8a4af7743f0
parent 864bea070af30ab3c763f110a323fa7b128e4038
Author: Christian Grothoff <christian@grothoff.org>
Date: Mon, 3 Sep 2012 14:06:39 +0000
-simplify logic
Diffstat:
1 file changed, 7 insertions(+), 9 deletions(-)
diff --git a/src/main/extractor_datasource.c b/src/main/extractor_datasource.c
@@ -320,15 +320,13 @@ static int64_t
bfds_seek (struct BufferedFileDataSource *bfds,
int64_t pos, int whence)
{
+ uint64_t npos;
+
switch (whence)
{
case SEEK_CUR:
- if (bfds->fpos + bfds->buffer_pos + pos < 0)
- {
- LOG ("Invalid seek operation\n");
- return -1;
- }
- if (bfds->fpos + bfds->buffer_pos + pos > bfds->fsize)
+ npos = bfds->fpos + bfds->buffer_pos + pos;
+ if (npos > bfds->fsize)
{
LOG ("Invalid seek operation to %lld from %llu (max is %llu)\n",
(long long) pos,
@@ -341,15 +339,15 @@ bfds_seek (struct BufferedFileDataSource *bfds,
(bfds->buffer_pos + pos >= 0) ) )
{
bfds->buffer_pos += pos;
- return bfds->buffer_pos + bfds->fpos;
+ return npos;
}
if (0 != bfds_pick_next_buffer_at (bfds,
- bfds->fpos + bfds->buffer_pos + pos))
+ npos))
{
LOG ("seek operation failed\n");
return -1;
}
- return bfds->fpos;
+ return npos;
case SEEK_END:
if (pos > 0)
{