From: Marcus Brinkmann Date: Thu, 23 Sep 2004 17:54:26 +0000 (+0000) Subject: 2004-09-23 Marcus Brinkmann X-Git-Tag: gpgme-1-0-0~16 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=4b8e1217fc9ea7ef49ce048fc1e466d7ea568d26;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/gpgme/ChangeLog b/gpgme/ChangeLog index 02bb5d6..039b197 100644 --- a/gpgme/ChangeLog +++ b/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/gpgme/data-stream.c b/gpgme/data-stream.c index c28f5ff..3abecaa 100644 --- a/gpgme/data-stream.c +++ b/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/gpgme/data.c b/gpgme/data.c index 80a3fb4..aba1986 100644 --- a/gpgme/data.c +++ b/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/gpgme/data.h b/gpgme/data.h index 57815ef..51d89aa 100644 --- a/gpgme/data.h +++ b/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. */