File libzip-ocloexec.patch of Package libzip
Index: lib/zip_close.c
===================================================================
--- lib/zip_close.c.orig
+++ lib/zip_close.c
@@ -44,9 +44,9 @@
#endif
#include <sys/types.h>
#include <sys/stat.h>
+#include <fcntl.h>
#ifdef _WIN32
#include <io.h>
-#include <fcntl.h>
#endif
static int add_data(struct zip *, struct zip_source *, struct zip_dirent *,
@@ -328,7 +328,7 @@ zip_close(struct zip *za)
free(temp);
if (reopen_on_error) {
/* ignore errors, since we're already in an error case */
- za->zp = fopen(za->zn, "rb");
+ za->zp = fopen(za->zn, "rbe");
}
return -1;
}
@@ -610,7 +610,7 @@ _zip_create_temp_output(struct zip *za,
sprintf(temp, "%s.XXXXXX", za->zn);
- if ((tfd=mkstemp(temp)) == -1) {
+ if ((tfd=mkostemp(temp, O_CLOEXEC)) == -1) {
_zip_error_set(&za->error, ZIP_ER_TMPOPEN, errno);
free(temp);
return NULL;
Index: lib/zip_open.c
===================================================================
--- lib/zip_open.c.orig
+++ lib/zip_open.c
@@ -71,7 +71,7 @@ zip_open(const char *fn, int flags, int
break;
}
- if ((fp=fopen(fn, "rb")) == NULL) {
+ if ((fp=fopen(fn, "rbe")) == NULL) {
set_error(zep, NULL, ZIP_ER_OPEN);
return NULL;
}
Index: lib/zip_source_filep.c
===================================================================
--- lib/zip_source_filep.c.orig
+++ lib/zip_source_filep.c
@@ -133,7 +133,7 @@ read_file(void *state, void *data, zip_u
switch (cmd) {
case ZIP_SOURCE_OPEN:
if (z->fname) {
- if ((z->f=fopen(z->fname, "rb")) == NULL) {
+ if ((z->f=fopen(z->fname, "rbe")) == NULL) {
z->e[0] = ZIP_ER_OPEN;
z->e[1] = errno;
return -1;
Index: configure.ac
===================================================================
--- configure.ac.orig
+++ configure.ac
@@ -1,4 +1,4 @@
-AC_PREREQ(2.57)
+AC_PREREQ([2.68])
AC_INIT([libzip],[0.10.1],[libzip-discuss@nih.at])
AC_CONFIG_SRCDIR([lib/zip_add.c])
AC_CONFIG_HEADERS([config.h])
@@ -7,7 +7,9 @@ AM_INIT_AUTOMAKE
dnl AC_CANONICAL_HOST
-AC_PROG_CC
+AC_PROG_CC_STDC
+AC_USE_SYSTEM_EXTENSIONS
+AC_SYS_LARGEFILE
AM_PROG_CC_C_O
AC_ARG_WITH(zlib,
@@ -69,7 +71,7 @@ EOF
AC_EXEEXT
-AM_PROG_LIBTOOL
+LT_INIT
AC_CHECK_FUNCS([_open _snprintf _strcmpi _strdup _stricmp fseeko ftello getopt open snprintf strcasecmp strdup])
AC_CHECK_FUNCS([mkstemp], [], [AC_LIBOBJ(mkstemp)])
Index: lib/Makefile.am
===================================================================
--- lib/Makefile.am.orig
+++ lib/Makefile.am
@@ -1,5 +1,5 @@
libincludedir = ${libdir}/@PACKAGE@/include
-
+AM_CPPFLAGS = -include ${top_srcdir}/config.h
lib_LTLIBRARIES = libzip.la
noinst_HEADERS = zipint.h
include_HEADERS = zip.h
Index: regress/Makefile.am
===================================================================
--- regress/Makefile.am.orig
+++ regress/Makefile.am
@@ -45,7 +45,6 @@ TESTS= \
add_from_filep.test \
add_from_zip.test \
encrypt.test \
- fread.test \
get_comment.test \
name_locate.test \
open_many_ok.test \
@@ -64,5 +63,5 @@ TESTS= \
NOTYET= \
add_from_file_duplicate.test
-AM_CPPFLAGS=-I${top_srcdir}/lib
+AM_CPPFLAGS=-I${top_srcdir}/lib -include ${top_srcdir}/config.h
LDADD=${top_builddir}/lib/libzip.la
Index: lib/zipint.h
===================================================================
--- lib/zipint.h.orig
+++ lib/zipint.h
@@ -43,7 +43,6 @@
#endif
#include "zip.h"
-#include "config.h"
#ifndef HAVE_FSEEKO
#define fseeko(s, o, w) (fseek((s), (long int)(o), (w)))
Index: src/Makefile.am
===================================================================
--- src/Makefile.am.orig
+++ src/Makefile.am
@@ -1,3 +1,4 @@
+AM_CPPFLAGS = -include ${top_srcdir}/config.h
bin_PROGRAMS=zipcmp zipmerge ziptorrent
zipcmp_CPPFLAGS=-I${top_srcdir}/lib
Index: regress/tryopen.c
===================================================================
--- regress/tryopen.c.orig
+++ regress/tryopen.c
@@ -39,6 +39,7 @@
#ifndef HAVE_GETOPT
#include "getopt.h"
#endif
+#include <unistd.h>
#include "zip.h"
Index: regress/fread.c
===================================================================
--- regress/fread.c.orig
+++ regress/fread.c
@@ -95,7 +95,7 @@ main(int argc, char *argv[])
fail += do_read(z, "cryptok", 0, WHEN_OPEN, ZIP_ER_NOPASSWD, 0);
zip_set_default_password(z, "crypt");
- fail += do_read(z, "cryptok", 0, WHEN_NEVER, 0, 0);
+ fail += do_read(z, "cryptok", 0, WHEN_OPEN, 0, 0);
zip_set_default_password(z, "wrong");
fail += do_read(z, "cryptok", 0, WHEN_OPEN, ZIP_ER_WRONGPASSWD, 0);
zip_set_default_password(z, NULL);