Add zip_ftell.
diff --git a/NEWS.md b/NEWS.md index 7891f53..627f9e3 100644 --- a/NEWS.md +++ b/NEWS.md
@@ -4,6 +4,7 @@ * Support legacy zip files with >64k entries. * Fix seeking in zip_source_file if start > 0. * Add zip_fseek() for seeking in uncompressed data. +* Add zip_ftell() for telling position in uncompressed data. 1.1.3 [2016-05-28] ==================
diff --git a/lib/Makefile.am b/lib/Makefile.am index 5e78f28..38ffad9 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am
@@ -63,6 +63,7 @@ zip_fopen_index_encrypted.c \ zip_fread.c \ zip_fseek.c \ + zip_ftell.c \ zip_get_archive_comment.c \ zip_get_archive_flag.c \ zip_get_compression_implementation.c \
diff --git a/lib/zip.h b/lib/zip.h index 96ba17c..7a87e28 100644 --- a/lib/zip.h +++ b/lib/zip.h
@@ -362,6 +362,7 @@ ZIP_EXTERN zip_file_t *zip_fopen_index_encrypted(zip_t *, zip_uint64_t, zip_flags_t, const char *); ZIP_EXTERN zip_int64_t zip_fread(zip_file_t *, void *, zip_uint64_t); ZIP_EXTERN zip_int8_t zip_fseek(zip_file_t *, zip_int64_t, int); +ZIP_EXTERN zip_int64_t zip_ftell(zip_file_t *); ZIP_EXTERN const char *zip_get_archive_comment(zip_t *, int *, zip_flags_t); ZIP_EXTERN int zip_get_archive_flag(zip_t *, zip_flags_t, zip_flags_t); ZIP_EXTERN const char *zip_get_name(zip_t *, zip_uint64_t, zip_flags_t);
diff --git a/lib/zip_ftell.c b/lib/zip_ftell.c new file mode 100644 index 0000000..895ce81 --- /dev/null +++ b/lib/zip_ftell.c
@@ -0,0 +1,61 @@ +/* + zip_ftell.c -- tell position in file + Copyright (C) 2016 Dieter Baron and Thomas Klausner + + This file is part of libzip, a library to manipulate ZIP archives. + The authors can be contacted at <libzip@nih.at> + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + 3. The names of the authors may not be used to endorse or promote + products derived from this software without specific prior + written permission. + + THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS + OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER + IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + + +#include "zipint.h" +#include <stdio.h> + +ZIP_EXTERN zip_int64_t +zip_ftell(zip_file_t *zf) +{ + zip_int64_t res; + + if (!zf) + return -1; + + if (zf->error.zip_err != 0) + return -1; + + if ((zip_source_supports(zf->src) & ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_TELL)) == 0) { + zip_error_set(&zf->error, ZIP_ER_OPNOTSUPP, 0); + return -1; + } + + res = zip_source_tell(zf->src); + if (res < 0) { + _zip_error_set_from_source(&zf->error, zf->src); + return -1; + } + + return res; +}
diff --git a/man/Makefile.am b/man/Makefile.am index 418a906..2ceb27c 100644 --- a/man/Makefile.am +++ b/man/Makefile.am
@@ -47,6 +47,7 @@ zip_fopen_encrypted.mdoc \ zip_fread.mdoc \ zip_fseek.mdoc \ + zip_ftell.mdoc \ zip_get_archive_comment.mdoc \ zip_get_archive_flag.mdoc \ zip_get_error.mdoc \
diff --git a/man/libzip.mdoc b/man/libzip.mdoc index c3dafa9..2c64f08 100644 --- a/man/libzip.mdoc +++ b/man/libzip.mdoc
@@ -29,7 +29,7 @@ .\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN .\" IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" -.Dd January 19, 2016 +.Dd October 1, 2016 .Dt LIBZIP 3 .Os .Sh NAME @@ -74,6 +74,10 @@ .Xr zip_fopen_index 3 .Xr zip_fopen_index_encrypted 3 .Xr zip_fread 3 +.Xr zip_fseek 3 +(uncompressed files only) +.Xr zip_ftell 3 +(uncompressed files only) .Xr zip_fclose 3 .Ss close archive .Xr zip_close 3
diff --git a/man/zip_fseek.mdoc b/man/zip_fseek.mdoc index 5ca87d1..7bd371e 100644 --- a/man/zip_fseek.mdoc +++ b/man/zip_fseek.mdoc
@@ -29,7 +29,7 @@ .\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN .\" IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" -.Dd September 12, 2016 +.Dd October 1, 2016 .Dt ZIP_FSEEK 3 .Os .Sh NAME @@ -62,8 +62,9 @@ .Sh SEE ALSO .Xr libzip 3 , .Xr zip_fclose 3 , +.Xr zip_fopen 3 , .Xr zip_fread 3 , -.Xr zip_fopen 3 +.Xr zip_ftell 3 .Sh AUTHORS .An -nosplit .An Dieter Baron Aq Mt dillo@nih.at
diff --git a/man/zip_ftell.mdoc b/man/zip_ftell.mdoc new file mode 100644 index 0000000..6aeeabf --- /dev/null +++ b/man/zip_ftell.mdoc
@@ -0,0 +1,67 @@ +.\" zip_ftell.mdoc -- tell position in file +.\" Copyright (C) 2016 Dieter Baron and Thomas Klausner +.\" +.\" This file is part of libzip, a library to manipulate ZIP archives. +.\" The authors can be contacted at <libzip@nih.at> +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in +.\" the documentation and/or other materials provided with the +.\" distribution. +.\" 3. The names of the authors may not be used to endorse or promote +.\" products derived from this software without specific prior +.\" written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS +.\" OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +.\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY +.\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE +.\" GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER +.\" IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +.\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN +.\" IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +.\" +.Dd October 1, 2016 +.Dt ZIP_FTELL 3 +.Os +.Sh NAME +.Nm zip_ftell +.Nd tell position in file +.Sh LIBRARY +libzip (-lzip) +.Sh SYNOPSIS +.In zip.h +.Ft zip_int64_t +.Fn zip_ftell "zip_file_t *file" +.Sh DESCRIPTION +The +.Fn zip_ftell +function reports the current offset in the file. +.Pp +.Nm +only works on uncompressed (stored) data. +When called on compressed data it will return an error. +.Sh RETURN VALUES +If successful, +.Nm +returns the current file position. +Otherwise, \-1 is returned. +.Sh SEE ALSO +.Xr libzip 3 , +.Xr zip_fclose 3 , +.Xr zip_fopen 3 , +.Xr zip_fread 3 , +.Xr zip_fseek 3 +.Sh AUTHORS +.An -nosplit +.An Dieter Baron Aq Mt dillo@nih.at +and +.An Thomas Klausner Aq Mt tk@giga.or.at