2004-09-23 Marcus Brinkmann <marcus@g10code.de>

* 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.
This commit is contained in:
Marcus Brinkmann 2004-09-23 17:54:26 +00:00
parent 497b0f8bd8
commit 4b8e1217fc
4 changed files with 32 additions and 5 deletions

View File

@ -1,3 +1,13 @@
2004-09-23 Marcus Brinkmann <marcus@g10code.de>
* 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 <marcus@g10code.de>
* gpgme.m4: Add copyright notice.

View File

@ -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);
}

View File

@ -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;
}

View File

@ -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. */