From 27ce1e3049b52e8b1bd641255308ff44e0c0a013 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Mon, 14 Apr 2014 17:26:16 +0200 Subject: [PATCH] zzip: add zzip_pread() prototype --- zzip/file.c | 10 ++++++++++ zzip/zzip.h | 8 ++++++++ 2 files changed, 18 insertions(+) diff --git a/zzip/file.c b/zzip/file.c index d4a7542..2ea3a5b 100644 --- a/zzip/file.c +++ b/zzip/file.c @@ -486,6 +486,16 @@ zzip_read(ZZIP_FILE * fp, void *buf, zzip_size_t len) } } +zzip_size_t +zzip_pread(ZZIP_FILE *file, void *ptr, zzip_size_t size, zzip_off_t offset) +{ + zzip_off_t new_offset = zzip_seek(file, offset, SEEK_SET); + if (new_offset < 0) + return -1; + + return zzip_read(file, ptr, size); +} + /** => zzip_read */ zzip_size_t diff --git a/zzip/zzip.h b/zzip/zzip.h index 3941acc..1191b7f 100644 --- a/zzip/zzip.h +++ b/zzip/zzip.h @@ -180,6 +180,14 @@ int zzip_close(ZZIP_FILE * fp); _zzip_export zzip_ssize_t zzip_read(ZZIP_FILE * fp, void * buf, zzip_size_t len); +/* + * Read data from the specified offset. Depending on the + * implementation, this may or may not move the file pointer. + */ +_zzip_export +zzip_size_t +zzip_pread(ZZIP_FILE *file, void *ptr, zzip_size_t size, zzip_off_t offset); + /* * the stdc variant to open/read/close files. - Take note of the freopen() * call as it may reuse an existing preparsed copy of a zip central directory -- 2.40.0