Subject: [alpine-aports] [PATCH] main/libbsd: update to version 0.7.0

From: Andrew Hills <[email-masked]>
Date: Thu, 4 Jun 2015 13:54:32 +0000

References to funopen() were all removed, since libbsd's implementation
depends on glibc's fopencookie().
---
 main/libbsd/APKBUILD                               |  24 +-
 ...rce_setproctitle_into_.init_array_section.patch |  77 ---
 main/libbsd/remove-funopen.patch                   | 720 +++++++++++++++++++++
 3 files changed, 732 insertions(+), 89 deletions(-)
 delete mode 100644 main/libbsd/Revert_Force_setproctitle_into_.init_array_section.patch
 create mode 100644 main/libbsd/remove-funopen.patch

diff --git a/main/libbsd/APKBUILD b/main/libbsd/APKBUILD
index 0b63168..77ea82d 100644
--- a/main/libbsd/APKBUILD
+++ b/main/libbsd/APKBUILD
@@ -1,8 +1,8 @@
 # Contributor: William Pitcock <[email-masked]>
 # Maintainer: William Pitcock <[email-masked]>
 pkgname=libbsd
-pkgver=0.6.0
-pkgrel=1
+pkgver=0.7.0
+pkgrel=0
 pkgdesc="commonly-used BSD functions not implemented by all libcs"
 url="http://libbsd.freedesktop.org/"
 arch="x86 x86_64"
@@ -14,8 +14,8 @@ makedepends="$depends_dev autoconf automake libtool bsd-compat-headers
 install=""
 subpackages="$pkgname-dev $pkgname-doc"
 source="http://libbsd.freedesktop.org/releases/libbsd-$pkgver.tar.xz
-	Revert_Force_setproctitle_into_.init_array_section.patch
 	musl-fix-headers.patch
+	remove-funopen.patch
 	"
 
 _builddir="$srcdir"/libbsd-$pkgver
@@ -49,12 +49,12 @@ package() {
 	rm -f "$pkgdir"/usr/lib/*.la
 }
 
-md5sums="f6c75f0a9818e323a589bcbd560a0eb4  libbsd-0.6.0.tar.xz
-628a86066f8a1222c7ffee5aa3d488ef  Revert_Force_setproctitle_into_.init_array_section.patch
-712fca9c718f8b0f4d664c214072d6b3  musl-fix-headers.patch"
-sha256sums="9e8f34ffa9c8579c87965a55a82d8ac37a1dc64858f717b7c49452ade277cc62  libbsd-0.6.0.tar.xz
-a4497defcc14d04e407130931ed89c6b9e5e79c684884291cc080c6e90c82777  Revert_Force_setproctitle_into_.init_array_section.patch
-3082d5f47c6d895dc3546d517ba7d541602872f00d5b39852a0b28b3d74ce954  musl-fix-headers.patch"
-sha512sums="d750ead28e76938ab8d9c5575c1c87bcf275754f9f82b19d647f522bfaf07e5a85dc47ed5faae093994e5456be806fdebb55eeeed74efff3c950dfb6142e2b5c  libbsd-0.6.0.tar.xz
-52d3e69a2589dc299bcc5ca99bcf595d054be4c8b6b2ce4101d7657a54fecc4bc843b4439f0c9b582266559288220b342f926e700e7ae7e91bf29f0ae30d707f  Revert_Force_setproctitle_into_.init_array_section.patch
-87a4337108776cf8ff05be5938b3c8a548a4dd5625ae8e4afbab54c4c06af287188a81213633540a82c07e90b028b616f30934b02e8ab7485efa0ae0afdf20ee  musl-fix-headers.patch"
+md5sums="fcceb4e66fd448ca4ed42ba22a8babb0  libbsd-0.7.0.tar.xz
+712fca9c718f8b0f4d664c214072d6b3  musl-fix-headers.patch
+c3bbb840dfd7dd05c87ad4da80e6baf2  remove-funopen.patch"
+sha256sums="0f3b0e17e5c34c038126e0a04351b11e23c6101a7d0ce3beeab29bb6415c10bb  libbsd-0.7.0.tar.xz
+3082d5f47c6d895dc3546d517ba7d541602872f00d5b39852a0b28b3d74ce954  musl-fix-headers.patch
+8933824671a528226568cfab9adbd9a30c970fa74718279d5735d49b521583c3  remove-funopen.patch"
+sha512sums="2c4c8fb2ae7fb5e5aab90f7a59a679220922dfeeaf0d54f80976914fcd507171bb9359f0837c32499e63a0f3e9342c9dcd387a466b359d20e3790ddc8ca17cea  libbsd-0.7.0.tar.xz
+87a4337108776cf8ff05be5938b3c8a548a4dd5625ae8e4afbab54c4c06af287188a81213633540a82c07e90b028b616f30934b02e8ab7485efa0ae0afdf20ee  musl-fix-headers.patch
+41f51507086f357b8310ada33190a41d1eee02e21259cf101ab46bd18e25bd4aab8b56abee3d4e0f9576a7e224de61c8cf248a2f83a7feae1d9f22fff54d682c  remove-funopen.patch"
diff --git a/main/libbsd/Revert_Force_setproctitle_into_.init_array_section.patch b/main/libbsd/Revert_Force_setproctitle_into_.init_array_section.patch
deleted file mode 100644
index 5d5b215..0000000
--- a/main/libbsd/Revert_Force_setproctitle_into_.init_array_section.patch
+++ /dev/null
@@ -1,77 +0,0 @@
-diff -rupN a/configure.ac b/configure.ac
---- a/configure.ac	2013-07-14 13:34:07.000000000 +0200
-+++ b/configure.ac	2013-11-12 10:27:39.986117039 +0100
-@@ -60,51 +60,6 @@ AC_CHECK_DECL([F_CLOSEM],
-               [#include <limits.h>
-                #include <fcntl.h>])
- 
--AC_CACHE_CHECK(
--	[for GNU .init_array section support],
--	[libbsd_cv_gnu_init_array_support],
--	[AC_RUN_IFELSE(
--		[AC_LANG_SOURCE(
--[[
--static int rc = 1;
--static void init(int argc) { if (argc == 1) rc = 0; }
--void (*init_func)(int argc) __attribute__((section(".init_array"))) = init;
--int main() { return rc; }
--]]
--		)],
--		[libbsd_cv_gnu_init_array_support=yes],
--		[libbsd_cv_gnu_init_array_support=no],
--		[AC_PREPROC_IFELSE(
--			[AC_LANG_SOURCE(
--[[
--/* Look for a known libc that supports .init_array with the GNU extension
-- * to pass main() arguments to the init functions. */
--#include <stdlib.h>
--#if defined __GLIBC_PREREQ
--#  if __GLIBC_PREREQ(2, 4)
--/* glibc supports GNU .init_array since 2.4. */
--#  else
--#    error glibc does not support GNU .init_array
--#  endif
--#else
--/*
-- * Basic SysV ABI .init_array support, init functions do not get arguments:
-- * - Bionic since its inception.
-- * - uClibc since 0.9.29.
-- */
--#  error unknown whether libc supports GNU .init_array
--#endif
--]]
--			)],
--			[libbsd_cv_gnu_init_array_support=yes],
--			[libbsd_cv_gnu_init_array_support=no])
--		]
--	)]
--)
--if test "$libbsd_cv_gnu_init_array_support" = no; then
--	AC_MSG_ERROR([missing required GNU .init_array section support])
--fi
--
- # Checks for library functions.
- AC_MSG_CHECKING([for program_invocation_short_name])
- AC_LINK_IFELSE(
-diff -rupN a/src/setproctitle.c b/src/setproctitle.c
---- a/src/setproctitle.c	2013-07-14 13:34:07.000000000 +0200
-+++ b/src/setproctitle.c	2013-11-12 10:28:55.332787881 +0100
-@@ -1,6 +1,6 @@
- /*
-  * Copyright © 2010 William Ahern
-- * Copyright © 2012-2013 Guillem Jover <[email-masked]>
-+ * Copyright © 2012 Guillem Jover <[email-masked]>
-  *
-  * Permission is hereby granted, free of charge, to any person obtaining a
-  * copy of this software and associated documentation files (the
-@@ -155,8 +155,8 @@ spt_copyargs(int argc, char *argv[])
- 	return 0;
- }
- 
--void
--setproctitle_init(int argc, char *argv[], char *envp[])
-+static void
-+spt_init(int argc, char *argv[], char *envp[])
- {
- 	char *base, *end, *nul, *tmp;
- 	int i, envc, error;
diff --git a/main/libbsd/remove-funopen.patch b/main/libbsd/remove-funopen.patch
new file mode 100644
index 0000000..d62877b
--- /dev/null
+++ b/main/libbsd/remove-funopen.patch
@@ -0,0 +1,720 @@
+diff -urN libbsd-0.7.0/include/bsd/stdio.h libbsd-0.7.0-patch/include/bsd/stdio.h
+--- libbsd-0.7.0/include/bsd/stdio.h	2013-10-21 03:42:04.000000000 +0000
++++ libbsd-0.7.0-patch/include/bsd/stdio.h	2015-06-04 13:32:20.978633262 +0000
+@@ -46,23 +46,6 @@
+ 
+ char *fgetln(FILE *fp, size_t *lenp);
+ 
+-/*
+- * Note: We diverge from the FreeBSD, OpenBSD and DragonFlyBSD declarations,
+- * because seekfn() there wrongly uses fpos_t, assuming it's an integral
+- * type, and any code using that on a system where fpos_t is a struct
+- * (such as GNU-based systems or NetBSD) will fail to build. In which case,
+- * as the code has to be modified anyway, we might just as well use the
+- * correct declaration here.
+- */
+-FILE *funopen(const void *cookie,
+-              int (*readfn)(void *cookie, char *buf, int size),
+-              int (*writefn)(void *cookie, const char *buf, int size),
+-              off_t (*seekfn)(void *cookie, off_t offset, int whence),
+-              int (*closefn)(void *cookie));
+-
+-#define fropen(cookie, fn) funopen(cookie, fn, NULL, NULL, NULL)
+-#define fwopen(cookie, fn) funopen(cookie, NULL, fn, NULL, NULL)
+-
+ int fpurge(FILE *fp);
+ __END_DECLS
+ 
+diff -urN libbsd-0.7.0/man/Makefile.am libbsd-0.7.0-patch/man/Makefile.am
+--- libbsd-0.7.0/man/Makefile.am	2014-07-17 03:06:29.000000000 +0000
++++ libbsd-0.7.0-patch/man/Makefile.am	2015-06-04 13:32:43.038680202 +0000
+@@ -28,7 +28,6 @@
+ 	flopen.3 \
+ 	fmtcheck.3 \
+ 	fparseln.3 \
+-	funopen.3 \
+ 	getbsize.3 \
+ 	getmode.3 \
+ 	getpeereid.3 \
+diff -urN libbsd-0.7.0/man/Makefile.in libbsd-0.7.0-patch/man/Makefile.in
+--- libbsd-0.7.0/man/Makefile.in	2014-07-29 01:19:59.000000000 +0000
++++ libbsd-0.7.0-patch/man/Makefile.in	2015-06-04 13:32:45.925353009 +0000
+@@ -282,7 +282,6 @@
+ 	flopen.3 \
+ 	fmtcheck.3 \
+ 	fparseln.3 \
+-	funopen.3 \
+ 	getbsize.3 \
+ 	getmode.3 \
+ 	getpeereid.3 \
+diff -urN libbsd-0.7.0/man/funopen.3 libbsd-0.7.0-patch/man/funopen.3
+--- libbsd-0.7.0/man/funopen.3	2013-10-21 03:42:04.000000000 +0000
++++ libbsd-0.7.0-patch/man/funopen.3	1970-01-01 00:00:00.000000000 +0000
+@@ -1,191 +0,0 @@
+-.\" Copyright (c) 1990, 1991, 1993
+-.\"	The Regents of the University of California.  All rights reserved.
+-.\"
+-.\" This code is derived from software contributed to Berkeley by
+-.\" Chris Torek.
+-.\" 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.
+-.\" 4. Neither the name of the University nor the names of its contributors
+-.\"    may be used to endorse or promote products derived from this software
+-.\"    without specific prior written permission.
+-.\"
+-.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 REGENTS OR CONTRIBUTORS 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.
+-.\"
+-.\"     @(#)funopen.3	8.1 (Berkeley) 6/9/93
+-.\" $FreeBSD$
+-.\"
+-.Dd March 19, 2004
+-.Dt FUNOPEN 3
+-.Os
+-.Sh NAME
+-.Nm funopen ,
+-.Nm fropen ,
+-.Nm fwopen
+-.Nd open a stream
+-.Sh LIBRARY
+-.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
+-.Lb libbsd
+-.Sh SYNOPSIS
+-.In bsd/stdio.h
+-.Ft FILE *
+-.Fn funopen "const void *cookie" "int (*readfn)(void *, char *, int)" "int (*writefn)(void *, const char *, int)" "off_t (*seekfn)(void *, off_t, int)" "int (*closefn)(void *)"
+-.Ft FILE *
+-.Fn fropen "void *cookie" "int (*readfn)(void *, char *, int)"
+-.Ft FILE *
+-.Fn fwopen "void *cookie" "int (*writefn)(void *, const char *, int)"
+-.Sh DESCRIPTION
+-The
+-.Fn funopen
+-function
+-associates a stream with up to four
+-.Dq Tn I/O No functions .
+-Either
+-.Fa readfn
+-or
+-.Fa writefn
+-must be specified;
+-the others can be given as an appropriately-typed
+-.Dv NULL
+-pointer.
+-These
+-.Tn I/O
+-functions will be used to read, write, seek and
+-close the new stream.
+-.Pp
+-In general, omitting a function means that any attempt to perform the
+-associated operation on the resulting stream will fail.
+-If the close function is omitted, closing the stream will flush
+-any buffered output and then succeed.
+-.Pp
+-The calling conventions of
+-.Fa readfn ,
+-.Fa writefn ,
+-.Fa seekfn
+-and
+-.Fa closefn
+-must match those, respectively, of
+-.Xr read 2 ,
+-.Xr write 2 ,
+-.Xr lseek 2 ,
+-and
+-.Xr close 2
+-with the single exception that they are passed the
+-.Fa cookie
+-argument specified to
+-.Fn funopen
+-in place of the traditional file descriptor argument.
+-.Pp
+-Read and write
+-.Tn I/O
+-functions are allowed to change the underlying buffer
+-on fully buffered or line buffered streams by calling
+-.Xr setvbuf 3 .
+-They are also not required to completely fill or empty the buffer.
+-They are not, however, allowed to change streams from unbuffered to buffered
+-or to change the state of the line buffering flag.
+-They must also be prepared to have read or write calls occur on buffers other
+-than the one most recently specified.
+-.Pp
+-All user
+-.Tn I/O
+-functions can report an error by returning \-1.
+-Additionally, all of the functions should set the external variable
+-.Va errno
+-appropriately if an error occurs.
+-.Pp
+-An error on
+-.Fn closefn
+-does not keep the stream open.
+-.Pp
+-As a convenience, the include file
+-.In stdio.h
+-defines the macros
+-.Fn fropen
+-and
+-.Fn fwopen
+-as calls to
+-.Fn funopen
+-with only a read or write function specified.
+-.Sh RETURN VALUES
+-Upon successful completion,
+-.Fn funopen
+-returns a
+-.Dv FILE
+-pointer.
+-Otherwise,
+-.Dv NULL
+-is returned and the global variable
+-.Va errno
+-is set to indicate the error.
+-.Sh ERRORS
+-.Bl -tag -width Er
+-.It Bq Er EINVAL
+-The
+-.Fn funopen
+-function
+-was called without either a read or write function.
+-The
+-.Fn funopen
+-function
+-may also fail and set
+-.Va errno
+-for any of the errors
+-specified for the routine
+-.Xr malloc 3 .
+-.El
+-.Sh SEE ALSO
+-.Xr fcntl 2 ,
+-.Xr open 2 ,
+-.Xr fclose 3 ,
+-.Xr fopen 3 ,
+-.Xr fseek 3 ,
+-.Xr setbuf 3
+-.Sh HISTORY
+-The
+-.Fn funopen
+-functions first appeared in
+-.Bx 4.4 .
+-.Sh BUGS
+-The
+-.Fn funopen
+-function
+-may not be portable to systems other than
+-.Bx .
+-.Pp
+-On
+-.Fx ,
+-.Ox
+-and
+-.Dx
+-the
+-.Fn funopen
+-interface erroneously assumes that
+-.Vt fpos_t
+-is an integral type, and uses it in the
+-.Fa seekfn
+-hook; but because code using a
+-.Fa seekfn
+-hook will fail to build on systems where
+-.Vt fpos_t
+-is a struct, and it will need to be slightly fixed anyway, the
+-implementation provided by libbsd (in the same way as
+-.Nx )
+-uses the correct
+-.Vt off_t
+-types.
+diff -urN libbsd-0.7.0/src/Makefile.am libbsd-0.7.0-patch/src/Makefile.am
+--- libbsd-0.7.0/src/Makefile.am	2014-07-20 00:08:02.000000000 +0000
++++ libbsd-0.7.0-patch/src/Makefile.am	2015-06-04 13:33:00.868718142 +0000
+@@ -56,7 +56,6 @@
+ 	fmtcheck.c \
+ 	fparseln.c \
+ 	fpurge.c \
+-	funopen.c \
+ 	getbsize.c \
+ 	getpeereid.c \
+ 	hash/md5.c \
+diff -urN libbsd-0.7.0/src/Makefile.in libbsd-0.7.0-patch/src/Makefile.in
+--- libbsd-0.7.0/src/Makefile.in	2014-07-29 01:19:59.000000000 +0000
++++ libbsd-0.7.0-patch/src/Makefile.in	2015-06-04 13:33:12.952077187 +0000
+@@ -142,7 +142,7 @@
+ am_libbsd_la_OBJECTS = arc4random.lo bsd_getopt.lo closefrom.lo \
+ 	dehumanize_number.lo err.lo expand_number.lo fgetln.lo \
+ 	fgetwln.lo flopen.lo fmtcheck.lo fparseln.lo fpurge.lo \
+-	funopen.lo getbsize.lo getpeereid.lo hash/md5.lo hash/md5hl.lo \
++	getbsize.lo getpeereid.lo hash/md5.lo hash/md5hl.lo \
+ 	heapsort.lo humanize_number.lo inet_net_pton.lo merge.lo \
+ 	nlist.lo pidfile.lo progname.lo radixsort.lo readpassphrase.lo \
+ 	reallocarray.lo reallocf.lo setmode.lo setproctitle.lo \
+@@ -376,7 +376,6 @@
+ 	fmtcheck.c \
+ 	fparseln.c \
+ 	fpurge.c \
+-	funopen.c \
+ 	getbsize.c \
+ 	getpeereid.c \
+ 	hash/md5.c \
+@@ -556,7 +555,6 @@
+ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fmtcheck.Plo@am__quote@
+ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fparseln.Plo@am__quote@
+ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fpurge.Plo@am__quote@
+-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/funopen.Plo@am__quote@
+ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/getbsize.Plo@am__quote@
+ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/getpeereid.Plo@am__quote@
+ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/heapsort.Plo@am__quote@
+diff -urN libbsd-0.7.0/src/funopen.c libbsd-0.7.0-patch/src/funopen.c
+--- libbsd-0.7.0/src/funopen.c	2013-10-21 03:42:04.000000000 +0000
++++ libbsd-0.7.0-patch/src/funopen.c	1970-01-01 00:00:00.000000000 +0000
+@@ -1,142 +0,0 @@
+-/*
+- * Copyright © 2011, 2013 Guillem Jover
+- *
+- * 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 name of the author may not be used to endorse or promote products
+- *    derived from this software without specific prior written permission.
+- *
+- * THIS SOFTWARE IS PROVIDED ``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 AUTHOR 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 <sys/cdefs.h>
+-#include <sys/types.h>
+-#include <errno.h>
+-#include <stdlib.h>
+-#include <stdio.h>
+-
+-#ifdef HAVE_FOPENCOOKIE
+-struct funopen_cookie {
+-	void *orig_cookie;
+-
+-	int (*readfn)(void *cookie, char *buf, int size);
+-	int (*writefn)(void *cookie, const char *buf, int size);
+-	off_t (*seekfn)(void *cookie, off_t offset, int whence);
+-	int (*closefn)(void *cookie);
+-};
+-
+-static ssize_t
+-funopen_read(void *cookie, char *buf, size_t size)
+-{
+-	struct funopen_cookie *cookiewrap = cookie;
+-
+-	if (cookiewrap->readfn == NULL) {
+-		errno = EBADF;
+-		return -1;
+-	}
+-
+-	return cookiewrap->readfn(cookiewrap->orig_cookie, buf, size);
+-}
+-
+-static ssize_t
+-funopen_write(void *cookie, const char *buf, size_t size)
+-{
+-	struct funopen_cookie *cookiewrap = cookie;
+-
+-	if (cookiewrap->writefn == NULL)
+-		return EOF;
+-
+-	return cookiewrap->writefn(cookiewrap->orig_cookie, buf, size);
+-}
+-
+-static int
+-funopen_seek(void *cookie, off64_t *offset, int whence)
+-{
+-	struct funopen_cookie *cookiewrap = cookie;
+-	off_t soff = *offset;
+-
+-	if (cookiewrap->seekfn == NULL) {
+-		errno = ESPIPE;
+-		return -1;
+-	}
+-
+-	soff = cookiewrap->seekfn(cookiewrap->orig_cookie, soff, whence);
+-	*offset = soff;
+-
+-	return *offset;
+-}
+-
+-static int
+-funopen_close(void *cookie)
+-{
+-	struct funopen_cookie *cookiewrap = cookie;
+-	int rc;
+-
+-	if (cookiewrap->closefn == NULL)
+-		return 0;
+-
+-	rc = cookiewrap->closefn(cookiewrap->orig_cookie);
+-
+-	free(cookiewrap);
+-
+-	return rc;
+-}
+-
+-FILE *
+-funopen(const void *cookie,
+-        int (*readfn)(void *cookie, char *buf, int size),
+-        int (*writefn)(void *cookie, const char *buf, int size),
+-        off_t (*seekfn)(void *cookie, off_t offset, int whence),
+-        int (*closefn)(void *cookie))
+-{
+-	struct funopen_cookie *cookiewrap;
+-	cookie_io_functions_t funcswrap = {
+-		.read = funopen_read,
+-		.write = funopen_write,
+-		.seek = funopen_seek,
+-		.close = funopen_close,
+-	};
+-	const char *mode;
+-
+-	if (readfn) {
+-		if (writefn == NULL)
+-			mode = "r";
+-		else
+-			mode = "r+";
+-	} else if (writefn) {
+-		mode = "w";
+-	} else {
+-		errno = EINVAL;
+-		return NULL;
+-	}
+-
+-	cookiewrap = malloc(sizeof(*cookiewrap));
+-	if (cookiewrap == NULL)
+-		return NULL;
+-
+-	cookiewrap->orig_cookie = (void *)cookie;
+-	cookiewrap->readfn = readfn;
+-	cookiewrap->writefn = writefn;
+-	cookiewrap->seekfn = seekfn;
+-	cookiewrap->closefn = closefn;
+-
+-	return fopencookie(cookiewrap, mode, funcswrap);
+-}
+-#else
+-#error "Function funopen() needs to be ported."
+-#endif
+diff -urN libbsd-0.7.0/src/libbsd.map libbsd-0.7.0-patch/src/libbsd.map
+--- libbsd-0.7.0/src/libbsd.map	2014-07-17 03:11:17.000000000 +0000
++++ libbsd-0.7.0-patch/src/libbsd.map	2015-06-04 13:33:26.058771740 +0000
+@@ -114,8 +114,6 @@
+ LIBBSD_0.7 {
+     getbsize;
+ 
+-    funopen;
+-
+     reallocarray;
+ 
+     sl_init;
+diff -urN libbsd-0.7.0/test/Makefile.am libbsd-0.7.0-patch/test/Makefile.am
+--- libbsd-0.7.0/test/Makefile.am	2014-07-20 00:06:41.000000000 +0000
++++ libbsd-0.7.0-patch/test/Makefile.am	2015-06-04 13:34:29.082239174 +0000
+@@ -13,7 +13,6 @@
+ 	endian \
+ 	humanize \
+ 	fgetln \
+-	funopen \
+ 	proctitle-init \
+ 	$(nil)
+ 
+@@ -23,7 +22,6 @@
+ 
+ humanize_LDFLAGS = $(top_builddir)/src/libbsd.la
+ fgetln_LDFLAGS = $(top_builddir)/src/libbsd.la
+-funopen_LDFLAGS = $(top_builddir)/src/libbsd.la
+ proctitle_init_SOURCES = proctitle.c
+ proctitle_init_CPPFLAGS = $(AM_CPPFLAGS) -DTEST_USE_SETPROCTITLE_INIT=1
+ proctitle_init_LDFLAGS = $(top_builddir)/src/libbsd.la
+diff -urN libbsd-0.7.0/test/Makefile.in libbsd-0.7.0-patch/test/Makefile.in
+--- libbsd-0.7.0/test/Makefile.in	2014-07-29 01:19:59.000000000 +0000
++++ libbsd-0.7.0-patch/test/Makefile.in	2015-06-04 13:34:16.542212491 +0000
+@@ -78,7 +78,7 @@
+ build_triplet = @build@
+ host_triplet = @host@
+ check_PROGRAMS = headers$(EXEEXT) overlay$(EXEEXT) endian$(EXEEXT) \
+-	humanize$(EXEEXT) fgetln$(EXEEXT) funopen$(EXEEXT) \
++	humanize$(EXEEXT) fgetln$(EXEEXT) \
+ 	proctitle-init$(EXEEXT) $(am__EXEEXT_1)
+ @BUILD_LIBBSD_CTOR_TRUE@am__append_1 = proctitle
+ subdir = test
+@@ -110,12 +110,6 @@
+ fgetln_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
+ 	$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
+ 	$(fgetln_LDFLAGS) $(LDFLAGS) -o $@
+-funopen_SOURCES = funopen.c
+-funopen_OBJECTS = funopen.$(OBJEXT)
+-funopen_LDADD = $(LDADD)
+-funopen_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
+-	$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
+-	$(funopen_LDFLAGS) $(LDFLAGS) -o $@
+ headers_SOURCES = headers.c
+ headers_OBJECTS = headers.$(OBJEXT)
+ headers_LDADD = $(LDADD)
+@@ -175,9 +169,9 @@
+ am__v_CCLD_ = $(am__v_CCLD_@AM_DEFAULT_V@)
+ am__v_CCLD_0 = @echo "  CCLD    " $@;
+ am__v_CCLD_1 = 
+-SOURCES = endian.c fgetln.c funopen.c headers.c humanize.c overlay.c \
++SOURCES = endian.c fgetln.c headers.c humanize.c overlay.c \
+ 	proctitle.c $(proctitle_init_SOURCES)
+-DIST_SOURCES = endian.c fgetln.c funopen.c headers.c humanize.c \
++DIST_SOURCES = endian.c fgetln.c headers.c humanize.c \
+ 	overlay.c proctitle.c $(proctitle_init_SOURCES)
+ am__can_run_installinfo = \
+   case $$AM_UPDATE_INFO_DIR in \
+@@ -532,7 +526,6 @@
+ 
+ humanize_LDFLAGS = $(top_builddir)/src/libbsd.la
+ fgetln_LDFLAGS = $(top_builddir)/src/libbsd.la
+-funopen_LDFLAGS = $(top_builddir)/src/libbsd.la
+ proctitle_init_SOURCES = proctitle.c
+ proctitle_init_CPPFLAGS = $(AM_CPPFLAGS) -DTEST_USE_SETPROCTITLE_INIT=1
+ proctitle_init_LDFLAGS = $(top_builddir)/src/libbsd.la
+@@ -595,10 +588,6 @@
+ 	@rm -f fgetln$(EXEEXT)
+ 	$(AM_V_CCLD)$(fgetln_LINK) $(fgetln_OBJECTS) $(fgetln_LDADD) $(LIBS)
+ 
+-funopen$(EXEEXT): $(funopen_OBJECTS) $(funopen_DEPENDENCIES) $(EXTRA_funopen_DEPENDENCIES) 
+-	@rm -f funopen$(EXEEXT)
+-	$(AM_V_CCLD)$(funopen_LINK) $(funopen_OBJECTS) $(funopen_LDADD) $(LIBS)
+-
+ headers$(EXEEXT): $(headers_OBJECTS) $(headers_DEPENDENCIES) $(EXTRA_headers_DEPENDENCIES) 
+ 	@rm -f headers$(EXEEXT)
+ 	$(AM_V_CCLD)$(LINK) $(headers_OBJECTS) $(headers_LDADD) $(LIBS)
+@@ -627,7 +616,6 @@
+ 
+ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/endian.Po@am__quote@
+ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fgetln.Po@am__quote@
+-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/funopen.Po@am__quote@
+ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/headers.Po@am__quote@
+ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/humanize.Po@am__quote@
+ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/overlay.Po@am__quote@
+@@ -905,13 +893,6 @@
+ 	$(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \
+ 	--log-file $$b.log --trs-file $$b.trs \
+ 	$(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \
+-	"$$tst" $(AM_TESTS_FD_REDIRECT)
+-funopen.log: funopen$(EXEEXT)
+-	@p='funopen$(EXEEXT)'; \
+-	b='funopen'; \
+-	$(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \
+-	--log-file $$b.log --trs-file $$b.trs \
+-	$(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \
+ 	"$$tst" $(AM_TESTS_FD_REDIRECT)
+ proctitle-init.log: proctitle-init$(EXEEXT)
+ 	@p='proctitle-init$(EXEEXT)'; \
+diff -urN libbsd-0.7.0/test/funopen.c libbsd-0.7.0-patch/test/funopen.c
+--- libbsd-0.7.0/test/funopen.c	2013-10-21 03:42:04.000000000 +0000
++++ libbsd-0.7.0-patch/test/funopen.c	1970-01-01 00:00:00.000000000 +0000
+@@ -1,178 +0,0 @@
+-/*
+- * Copyright © 2013 Guillem Jover <[email-masked]>
+- *
+- * 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 name of the author may not be used to endorse or promote products
+- *    derived from this software without specific prior written permission.
+- *
+- * THIS SOFTWARE IS PROVIDED ``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 AUTHOR 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 <assert.h>
+-#include <errno.h>
+-#include <string.h>
+-#include <stdio.h>
+-
+-#define ARRAY_SIZE 100
+-#define TEST_SIZE 50
+-
+-struct test_cookie {
+-	char array[ARRAY_SIZE];
+-	int index;
+-};
+-
+-int
+-test_readfn(void *cookie, char *buf, int size)
+-{
+-	struct test_cookie *tc = cookie;
+-	int left_size = sizeof(tc->array) - tc->index;
+-
+-	if (left_size < 0)
+-		size = 0;
+-	else if (left_size < size)
+-		size = left_size;
+-
+-	if (size > 0) {
+-		memcpy(buf, tc->array + tc->index, size);
+-		tc->index += size;
+-	}
+-
+-	return size;
+-}
+-
+-int
+-test_writefn(void *cookie, const char *buf, int size)
+-{
+-	struct test_cookie *tc = cookie;
+-	int left_size = sizeof(tc->array) - tc->index;
+-
+-	if (left_size < 0)
+-		size = 0;
+-	else if (left_size < size)
+-		size = left_size;
+-
+-	if (size > 0) {
+-		memcpy(tc->array + tc->index, buf, size);
+-		tc->index += size;
+-	}
+-
+-	return size;
+-}
+-
+-off_t
+-test_seekfn(void *cookie, off_t offset, int whence)
+-{
+-	struct test_cookie *tc = cookie;
+-
+-	switch (whence) {
+-	case SEEK_SET:
+-		tc->index = offset;
+-		break;
+-	case SEEK_CUR:
+-		tc->index += offset;
+-		break;
+-	case SEEK_END:
+-		tc->index = sizeof(tc->array) + offset;
+-		break;
+-	}
+-
+-	return tc->index;
+-}
+-
+-int
+-test_closefn(void *cookie)
+-{
+-	struct test_cookie *tc = cookie;
+-
+-	memset(tc->array, 0x7f, sizeof(tc->array));
+-
+-	return 0;
+-}
+-
+-int
+-main(int argc, char **argv)
+-{
+-	struct test_cookie tc;
+-	char data[ARRAY_SIZE];
+-	FILE *fp;
+-	size_t i;
+-
+-	/* Test invalid hooks. */
+-	fp = funopen(&tc, NULL, NULL, NULL, NULL);
+-	assert(fp == NULL);
+-	assert(errno == EINVAL);
+-
+-	/* Test read-only file. */
+-	tc.index = 0;
+-	for (i = 0; i < sizeof(tc.array); i++)
+-		tc.array[i] = i;
+-
+-	fp = fropen(&tc, test_readfn);
+-	assert(fp);
+-
+-	assert(fread(data, 1, TEST_SIZE, fp) == TEST_SIZE);
+-	assert(memcmp(tc.array, data, TEST_SIZE) == 0);
+-
+-	assert(fwrite(data, 1, TEST_SIZE, fp) == 0);
+-
+-	assert(fclose(fp) == 0);
+-
+-	/* Test write-only file. */
+-	memset(&tc, 0, sizeof(tc));
+-
+-	fp = fwopen(&tc, test_writefn);
+-	assert(fp);
+-
+-	setvbuf(fp, NULL, _IONBF, 0);
+-
+-	assert(fwrite(data, 1, TEST_SIZE, fp) == TEST_SIZE);
+-	assert(memcmp(tc.array, data, TEST_SIZE) == 0);
+-
+-	assert(fread(data, 1, TEST_SIZE, fp) == 0);
+-
+-	assert(fclose(fp) == 0);
+-
+-	/* Test seekable file. */
+-	memset(&tc, 0, sizeof(tc));
+-
+-	fp = funopen(&tc, test_readfn, test_writefn, test_seekfn, NULL);
+-	assert(fp);
+-
+-	setvbuf(fp, NULL, _IONBF, 0);
+-
+-	assert(fwrite(data, 1, TEST_SIZE, fp) == TEST_SIZE);
+-	assert(fseek(fp, 0L, SEEK_SET) == 0);
+-	assert(fwrite(data, 1, ARRAY_SIZE, fp) == ARRAY_SIZE);
+-	assert(memcmp(tc.array, data, ARRAY_SIZE) == 0);
+-
+-	assert(fread(data, 1, TEST_SIZE, fp) == 0);
+-
+-	assert(fclose(fp) == 0);
+-
+-	/* Test close hook. */
+-	memset(&tc, 0, sizeof(tc));
+-
+-	fp = funopen(&tc, test_readfn, test_writefn, NULL, test_closefn);
+-	assert(fclose(fp) == 0);
+-
+-	for (i = 0; i < sizeof(tc.array); i++)
+-		assert(tc.array[i] == 0x7f);
+-
+-	return 0;
+-}
-- 
2.4.2

---
Unsubscribe:  [email-masked]
Help:         [email-masked]
---