]> granicus.if.org Git - zziplib/commitdiff
zzip: add zzip_pread() prototype
authorMax Kellermann <max.kellermann@gmail.com>
Mon, 14 Apr 2014 15:26:16 +0000 (17:26 +0200)
committerMax Kellermann <max.kellermann@gmail.com>
Thu, 14 May 2020 19:03:10 +0000 (21:03 +0200)
zzip/file.c
zzip/zzip.h

index d4a7542518549c9d1bb1ccd8e36430c9aba5bd20..2ea3a5bee5d98bd3e2c5535fb6494825c8043be4 100644 (file)
@@ -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
index 3941acc70110fa59ab21f34e35503b1d2420b885..1191b7f2b246095d6d19d9bb7ac2efff36653769 100644 (file)
@@ -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