First part of API cleanup: no off_t.
Create and install zipconf.h, which contains definition for
fixed-sized integer types: zip_{,u}int{8,16,32,64}_t. On systems
where {,u}int{8,16,32,64}_t are defined, they are typedef'ed to
them, on other systems they are typedef'ed to a suitable integer
type.
XXX: Make use of these types internally.
--HG--
branch : HEAD
diff --git a/.hgignore b/.hgignore
index d23e0d4..453464a 100644
--- a/.hgignore
+++ b/.hgignore
@@ -14,6 +14,7 @@
^libtool$
^stamp-h1$
^lib/zip_err_str\.c$
+^lib/zipconf\.h$
^man/.*\.html$
^regress/add_dir$
^regress/add_from_buffer$
diff --git a/TODO b/TODO
index 802d6d6..f2df409 100644
--- a/TODO
+++ b/TODO
@@ -1,4 +1,3 @@
-+ [portability] no off_t in API
+ [portability] use _setmode(_fileno(fp), _O_BINARY); where present
+ [bug] _zip_checkcons return value can overflow
+ [bug] _zip_u2d_time: handle localtime(3) failure
diff --git a/configure.ac b/configure.ac
index 6d1db2a..38498b0 100644
--- a/configure.ac
+++ b/configure.ac
@@ -54,6 +54,20 @@
AC_CHECK_HEADERS([unistd.h])
+AC_CHECK_TYPES([int8_t])
+AC_CHECK_TYPES([int16_t])
+AC_CHECK_TYPES([int32_t])
+AC_CHECK_TYPES([int64_t])
+AC_CHECK_TYPES([uint8_t])
+AC_CHECK_TYPES([uint16_t])
+AC_CHECK_TYPES([uint32_t])
+AC_CHECK_TYPES([uint64_t])
+
+AC_CHECK_SIZEOF([short])
+AC_CHECK_SIZEOF([int])
+AC_CHECK_SIZEOF([long])
+AC_CHECK_SIZEOF([long long])
+
AC_STRUCT_TIMEZONE
case $host_os
diff --git a/lib/Makefile.am b/lib/Makefile.am
index 5a6d095..5e4d3a6 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -1,6 +1,9 @@
+libincludedir = ${libdir}/include/@PACKAGE@
+
lib_LTLIBRARIES = libzip.la
noinst_HEADERS = zipint.h
include_HEADERS = zip.h
+libinclude_HEADERS = zipconf.h
libzip_la_LDFLAGS=-no-undefined -version-info 1:0
libzip_la_LIBADD=@LTLIBOBJS@
@@ -60,10 +63,13 @@
zip_unchange_archive.c \
zip_unchange_data.c
-BUILT_SOURCES=zip_err_str.c
+BUILT_SOURCES=zip_err_str.c zipconf.h
EXTRA_DIST= CMakeLists.txt \
make_zip_err_str.sh
zip_err_str.c: zip.h make_zip_err_str.sh
sh $(srcdir)/make_zip_err_str.sh $(srcdir)/zip.h zip_err_str.c
+
+zipconf.h: ${top_builddir}/config.h make_zipconf.sh
+ sh ${srcdir}/make_zipconf.sh ${top_builddir}/config.h zipconf.h
diff --git a/lib/make_zipconf.sh b/lib/make_zipconf.sh
new file mode 100644
index 0000000..05bde12
--- /dev/null
+++ b/lib/make_zipconf.sh
@@ -0,0 +1,114 @@
+#!/bin/sh
+
+# make_zipconf.sh: create platform specific include file zipconf.h
+# Copyright (C) 1999-2008 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.
+
+
+set -e
+
+define_type()
+{
+ short=$1
+ long=$2
+ bytes=$3
+ infile="$4"
+ outfile="$5"
+
+ bits=`expr $bytes '*' 8`
+ type="${short}int${bits}_t"
+ TYPE=`echo $type | tr a-z A-Z`
+ if grep -q "define HAVE_${TYPE}" "$infile"
+ then
+ echo "typedef $type zip_$type;" >> "$outfile"
+ else
+ if [ "$bytes" -eq 1 ]
+ then
+ if [ -z "$long" ]
+ then
+ long='signed'
+ fi
+ echo "typedef $long char $type;" >> $outfile
+ else
+ ctype=`sed -n "s/.define SIZEOF_\([A-Z_]*\) $bytes/\1/p" "$infile" \
+ | head -1 | tr A-Z_ 'a-z '`
+ if [ -z "$ctype" ]
+ then
+ echo "$0: no $bits bit type found" >&2
+ exit 1
+ fi
+ echo "typedef $long $ctype $type;" >> $outfile
+ fi
+ fi
+}
+
+
+if [ "$#" -ne 2 ]
+then
+ echo "Usage: $0 config_h_file out_file" >&2
+ echo " e.g. $0 ../config.h zip_err_str.c" >&2
+ exit 1
+fi
+
+if [ "$1" = "$2" ]
+then
+ echo "$0: error: output file = input file" >&2
+ exit 1
+fi
+
+cat <<EOF > "$2.$$"
+#ifndef _HAD_ZIPCONF_H
+#define _HAD_ZIPCONF_H
+
+/*
+ zipconf.h -- platform specific include file
+
+ This file was generated automatically by $0
+ based on $1.
+ */
+
+EOF
+
+if grep -q 'define HAVE_INTTYPES_H' "$1"
+then
+ echo '#include <inttypes.h>' >> "$2.$$"
+ echo >> "$2.$$"
+fi
+
+for size in 1 2 4 8
+do
+ define_type '' '' $size "$1" "$2.$$"
+ define_type u unsigned $size "$1" "$2.$$"
+done
+
+echo >> "$2.$$"
+echo '#endif /* zipconf.h */' >> "$2.$$"
+
+mv "$2.$$" "$2"
diff --git a/lib/zip.h b/lib/zip.h
index 48431a3..e2ca987 100644
--- a/lib/zip.h
+++ b/lib/zip.h
@@ -48,6 +48,8 @@
extern "C" {
#endif
+#include <zipconf.h>
+
#include <sys/types.h>
#include <stdio.h>
#include <time.h>
@@ -163,12 +165,12 @@
struct zip_stat {
const char *name; /* name of the file */
int index; /* index within archive */
- unsigned int crc; /* crc of file data */
+ zip_uint32_t crc; /* crc of file data */
time_t mtime; /* modification time */
- off_t size; /* size of file (uncompressed) */
- off_t comp_size; /* size of file (compressed) */
- unsigned short comp_method; /* compression method used */
- unsigned short encryption_method; /* encryption method used */
+ zip_uint64_t size; /* size of file (uncompressed) */
+ zip_uint64_t comp_size; /* size of file (compressed) */
+ zip_uint16_t comp_method; /* compression method used */
+ zip_uint16_t encryption_method; /* encryption method used */
};
struct zip;
@@ -205,16 +207,16 @@
ZIP_EXTERN int zip_set_archive_flag(struct zip *, int, int);
ZIP_EXTERN int zip_set_file_comment(struct zip *, int, const char *, int);
ZIP_EXTERN struct zip_source *zip_source_buffer(struct zip *, const void *,
- off_t, int);
+ zip_uint64_t, int);
ZIP_EXTERN struct zip_source *zip_source_file(struct zip *, const char *,
- off_t, off_t);
+ zip_uint64_t, zip_int64_t);
ZIP_EXTERN struct zip_source *zip_source_filep(struct zip *, FILE *,
- off_t, off_t);
+ zip_uint64_t, zip_int64_t);
ZIP_EXTERN void zip_source_free(struct zip_source *);
ZIP_EXTERN struct zip_source *zip_source_function(struct zip *,
zip_source_callback, void *);
ZIP_EXTERN struct zip_source *zip_source_zip(struct zip *, struct zip *,
- int, int, off_t, off_t);
+ int, int, zip_uint64_t, zip_int64_t);
ZIP_EXTERN int zip_stat(struct zip *, const char *, int, struct zip_stat *);
ZIP_EXTERN int zip_stat_index(struct zip *, int, int, struct zip_stat *);
ZIP_EXTERN void zip_stat_init(struct zip_stat *);
diff --git a/lib/zip_source_buffer.c b/lib/zip_source_buffer.c
index 1e9121c..e2f1218 100644
--- a/lib/zip_source_buffer.c
+++ b/lib/zip_source_buffer.c
@@ -1,6 +1,6 @@
/*
zip_source_buffer.c -- create zip data source from buffer
- Copyright (C) 1999-2007 Dieter Baron and Thomas Klausner
+ Copyright (C) 1999-2008 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>
@@ -50,7 +50,7 @@
ZIP_EXTERN struct zip_source *
-zip_source_buffer(struct zip *za, const void *data, off_t len, int freep)
+zip_source_buffer(struct zip *za, const void *data, zip_uint64_t len, int freep)
{
struct read_data *f;
struct zip_source *zs;
@@ -58,7 +58,7 @@
if (za == NULL)
return NULL;
- if (len < 0 || (data == NULL && len > 0)) {
+ if (data == NULL && len > 0) {
_zip_error_set(&za->error, ZIP_ER_INVAL, 0);
return NULL;
}
diff --git a/lib/zip_source_file.c b/lib/zip_source_file.c
index eb1129a..973f133 100644
--- a/lib/zip_source_file.c
+++ b/lib/zip_source_file.c
@@ -41,12 +41,13 @@
ZIP_EXTERN struct zip_source *
-zip_source_file(struct zip *za, const char *fname, off_t start, off_t len)
+zip_source_file(struct zip *za, const char *fname, zip_uint64_t start,
+ zip_int64_t len)
{
if (za == NULL)
return NULL;
- if (fname == NULL || start < 0 || len < -1) {
+ if (fname == NULL || len < -1) {
_zip_error_set(&za->error, ZIP_ER_INVAL, 0);
return NULL;
}
diff --git a/lib/zip_source_filep.c b/lib/zip_source_filep.c
index 5373934..7959afc 100644
--- a/lib/zip_source_filep.c
+++ b/lib/zip_source_filep.c
@@ -44,9 +44,9 @@
struct read_file {
char *fname; /* name of file to copy from */
FILE *f; /* file to copy from */
- off_t off; /* start offset of */
- off_t len; /* lengt of data to copy */
- off_t remain; /* bytes remaining to be copied */
+ zip_uint64_t off; /* start offset of */
+ zip_int64_t len; /* lengt of data to copy */
+ zip_int64_t remain; /* bytes remaining to be copied */
int e[2]; /* error codes */
};
@@ -56,7 +56,8 @@
ZIP_EXTERN struct zip_source *
-zip_source_filep(struct zip *za, FILE *file, off_t start, off_t len)
+zip_source_filep(struct zip *za, FILE *file, zip_uint64_t start,
+ zip_int64_t len)
{
if (za == NULL)
return NULL;
@@ -73,7 +74,7 @@
struct zip_source *
_zip_source_file_or_p(struct zip *za, const char *fname, FILE *file,
- off_t start, off_t len)
+ zip_uint64_t start, zip_int64_t len)
{
struct read_file *f;
struct zip_source *zs;
@@ -130,7 +131,7 @@
}
}
- if (fseeko(z->f, z->off, SEEK_SET) < 0) {
+ if (fseeko(z->f, (off_t)z->off, SEEK_SET) < 0) {
z->e[0] = ZIP_ER_SEEK;
z->e[1] = errno;
return -1;
diff --git a/lib/zip_source_zip.c b/lib/zip_source_zip.c
index 3eef552..4d595be 100644
--- a/lib/zip_source_zip.c
+++ b/lib/zip_source_zip.c
@@ -41,7 +41,8 @@
struct read_zip {
struct zip_file *zf;
struct zip_stat st;
- off_t off, len;
+ zip_uint64_t off;
+ zip_int64_t len;
};
static ssize_t read_zip(void *st, void *data, size_t len,
@@ -51,7 +52,7 @@
ZIP_EXTERN struct zip_source *
zip_source_zip(struct zip *za, struct zip *srcza, int srcidx, int flags,
- off_t start, off_t len)
+ zip_uint64_t start, zip_int64_t len)
{
struct zip_error error;
struct zip_source *zs;
@@ -62,7 +63,7 @@
if (za == NULL)
return NULL;
- if (srcza == NULL || start < 0 || len < -1 || srcidx < 0 || srcidx >= srcza->nentry) {
+ if (srcza == NULL || len < -1 || srcidx < 0 || srcidx >= srcza->nentry) {
_zip_error_set(&za->error, ZIP_ER_INVAL, 0);
return NULL;
}
@@ -120,7 +121,8 @@
{
struct read_zip *z;
char b[8192], *buf;
- int i, n;
+ int i;
+ zip_uint64_t n;
z = (struct read_zip *)state;
buf = (char *)data;
diff --git a/lib/zipint.h b/lib/zipint.h
index d6cf4fe..da08ed7 100644
--- a/lib/zipint.h
+++ b/lib/zipint.h
@@ -245,7 +245,7 @@
int _zip_filerange_crc(FILE *, off_t, off_t, uLong *, struct zip_error *);
struct zip_source *_zip_source_file_or_p(struct zip *, const char *, FILE *,
- off_t, off_t);
+ zip_uint64_t, zip_int64_t);
void _zip_free(struct zip *);
const char *_zip_get_name(struct zip *, int, int, struct zip_error *);
diff --git a/libzip.pc.in b/libzip.pc.in
index ad1e565..f1301be 100644
--- a/libzip.pc.in
+++ b/libzip.pc.in
@@ -2,6 +2,7 @@
exec_prefix=@exec_prefix@
libdir=@libdir@
includedir=@includedir@
+libincludedir=@libdir@/libzip/include
zipcmp=@prefix@/bin/zipcmp
@@ -9,5 +10,5 @@
Description: library for handling zip archives
Version: @VERSION@
Libs: -L${libdir} -lzip @LIBS@
-Cflags: -I${includedir}
+Cflags: -I${includedir} -I${libincludedir}
diff --git a/man/zip_source_buffer.mdoc b/man/zip_source_buffer.mdoc
index e251896..b88b48b 100644
--- a/man/zip_source_buffer.mdoc
+++ b/man/zip_source_buffer.mdoc
@@ -1,7 +1,7 @@
.\" $NiH: zip_source_buffer.mdoc,v 1.5 2005/06/09 21:14:54 wiz Exp $
.\"
.\" zip_source_buffer.mdoc -- create zip data source from buffer
-.\" Copyright (C) 2004, 2005 Dieter Baron and Thomas Klausner
+.\" Copyright (C) 2004-2008 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>
@@ -31,7 +31,7 @@
.\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
.\" IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
-.Dd July 20, 2005
+.Dd August 1, 2008
.Dt ZIP_SOURCE_DATA 3
.Os
.Sh NAME
@@ -42,8 +42,8 @@
.Sh SYNOPSIS
.In zip.h
.Ft struct zip_source *
-.Fn zip_source_buffer "struct zip *archive" "const void *data" "off_t len" \
-"int freep"
+.Fn zip_source_buffer "struct zip *archive" "const void *data" \
+"zip_uint64_t len" "int freep"
.Sh DESCRIPTION
The function
.Fn zip_source_buffer
@@ -65,9 +65,6 @@
.Fn zip_source_buffer
fails if:
.Bl -tag -width Er
-.It Bq Er ZIP_ER_INVAL
-.Ar len
-is negative, or
.Ar len
is greater than zero and
.Ar data
diff --git a/man/zip_source_file.mdoc b/man/zip_source_file.mdoc
index d5fdd34..c109a98 100644
--- a/man/zip_source_file.mdoc
+++ b/man/zip_source_file.mdoc
@@ -1,7 +1,7 @@
.\" $NiH: zip_source_file.mdoc,v 1.8 2005/07/15 14:11:16 wiz Exp $
.\"
.\" zip_source_file.mdoc -- create data source from a file
-.\" Copyright (C) 2004, 2005 Dieter Baron and Thomas Klausner
+.\" Copyright (C) 2004-2008 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>
@@ -31,7 +31,7 @@
.\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
.\" IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
-.Dd July 20, 2005
+.Dd August 1, 2008
.Dt ZIP_SOURCE_FILE 3
.Os
.Sh NAME
@@ -41,7 +41,8 @@
libzip (-lzip)
.Sh SYNOPSIS
.Ft struct zip_source *
-.Fn zip_source_file "struct zip *archive" "const char *fname" "off_t start" "off_t len"
+.Fn zip_source_file "struct zip *archive" "const char *fname" \
+"zip_uint64_t start" "zip_int64_t len"
.Sh DESCRIPTION
The function
.Fn zip_source_file
@@ -59,6 +60,9 @@
is 0 or \-1, the whole file (starting from
.Ar start )
is used.
+.Pp
+The fie is opened and read when the data from the source is used, usually by
+.Fn zip_close .
.Sh RETURN VALUES
Upon successful completion, the created source is returned.
Otherwise,
diff --git a/man/zip_source_filep.mdoc b/man/zip_source_filep.mdoc
index f3d57ec..09044ea 100644
--- a/man/zip_source_filep.mdoc
+++ b/man/zip_source_filep.mdoc
@@ -1,7 +1,7 @@
.\" $NiH: zip_source_filep.mdoc,v 1.6 2005/06/09 21:14:54 wiz Exp $
.\"
.\" zip_source_filep.mdoc -- create data source from a file stream
-.\" Copyright (C) 2004, 2005 Dieter Baron and Thomas Klausner
+.\" Copyright (C) 2004-2008 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>
@@ -31,7 +31,7 @@
.\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
.\" IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
-.Dd July 20, 2005
+.Dd August 1, 2008
.Dt ZIP_SOURCE_FILEP 3
.Os
.Sh NAME
@@ -41,7 +41,8 @@
libzip (-lzip)
.Sh SYNOPSIS
.Ft struct zip_source *
-.Fn zip_source_filep "struct zip *archive" "FILE *file" "off_t start" "off_t len"
+.Fn zip_source_filep "struct zip *archive" "FILE *file" \
+"zip_uint64_t start" "zip_int64_t len"
.Sh DESCRIPTION
The function
.Fn zip_source_filep