+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.
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);
}
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;
}
/* Allocated size of BUFFER. */
size_t size;
size_t length;
- size_t offset;
+ off_t offset;
} mem;
/* For gpgme_data_new_from_read_cb. */