From: Marcus Brinkmann Date: Thu, 23 Sep 2004 17:54:26 +0000 (+0000) Subject: 2004-09-23 Marcus Brinkmann X-Git-Tag: gpgme-1.2.0@1385~400 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=6ec821677e9380f8a71cd97305791c96361162f3;p=gpgme.git 2004-09-23 Marcus Brinkmann * data-stream.c (stream_seek): Call ftello and return the current offset. * data.h (struct gpgme_data): Change type of data.mem.offset to off_t. * data.c (gpgme_data_seek): Check dh->cbs->seek callback, not read callback. If SEEK_CUR, adjust the offset by the pending buffer size. Clear pending buffer on success. --- diff --git a/trunk/gpgme/ChangeLog b/trunk/gpgme/ChangeLog index 02bb5d6..039b197 100644 --- a/trunk/gpgme/ChangeLog +++ b/trunk/gpgme/ChangeLog @@ -1,3 +1,13 @@ +2004-09-23 Marcus Brinkmann + + * data-stream.c (stream_seek): Call ftello and return the current + offset. + * data.h (struct gpgme_data): Change type of data.mem.offset to + off_t. + * data.c (gpgme_data_seek): Check dh->cbs->seek callback, not read + callback. If SEEK_CUR, adjust the offset by the pending buffer + size. Clear pending buffer on success. + 2004-09-14 Marcus Brinkmann * gpgme.m4: Add copyright notice. diff --git a/trunk/gpgme/data-stream.c b/trunk/gpgme/data-stream.c index c28f5ff..3abecaa 100644 --- a/trunk/gpgme/data-stream.c +++ b/trunk/gpgme/data-stream.c @@ -50,12 +50,19 @@ stream_write (gpgme_data_t dh, const void *buffer, size_t size) static off_t stream_seek (gpgme_data_t dh, off_t offset, int whence) { + int err; + #ifdef HAVE_FSEEKO - return fseeko (dh->data.stream, offset, whence); + err = fseeko (dh->data.stream, offset, whence); #else /* FIXME: Check for overflow, or at least bail at compilation. */ - return fseek (dh->data.stream, offset, whence); + err = fseek (dh->data.stream, offset, whence); #endif + + if (err) + return -1; + + return ftello (dh->data.stream); } diff --git a/trunk/gpgme/data.c b/trunk/gpgme/data.c index 80a3fb4..aba1986 100644 --- a/trunk/gpgme/data.c +++ b/trunk/gpgme/data.c @@ -112,12 +112,22 @@ gpgme_data_seek (gpgme_data_t dh, off_t offset, int whence) errno = EINVAL; return -1; } - if (!dh->cbs->read) + if (!dh->cbs->seek) { errno = EOPNOTSUPP; return -1; } - return (*dh->cbs->seek) (dh, offset, whence); + + /* For relative movement, we must take into account the actual + position of the read counter. */ + if (whence == SEEK_CUR) + offset -= dh->pending_len; + + offset = (*dh->cbs->seek) (dh, offset, whence); + if (offset >= 0) + dh->pending_len = 0; + + return offset; } diff --git a/trunk/gpgme/data.h b/trunk/gpgme/data.h index 57815ef..51d89aa 100644 --- a/trunk/gpgme/data.h +++ b/trunk/gpgme/data.h @@ -99,7 +99,7 @@ struct gpgme_data /* Allocated size of BUFFER. */ size_t size; size_t length; - size_t offset; + off_t offset; } mem; /* For gpgme_data_new_from_read_cb. */