Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)

libbsd: update patches

+206 -879
-222
pkgs/development/libraries/libbsd/cdefs.patch
··· 1 - From 11ec8f1e5dfa1c10e0c9fb94879b6f5b96ba52dd Mon Sep 17 00:00:00 2001 2 - From: Guillem Jover <guillem@hadrons.org> 3 - Date: Tue, 6 Mar 2018 01:41:35 +0100 4 - Subject: Handle systems missing <sys/cdefs.h> 5 - 6 - This is a non-portable header, and we cannot expect it to be provided by 7 - the system libc (e.g. musl). We just need and rely on declaration that 8 - we have defined ourselves in our own <bsd/sys/cdefs.h>. So we switch to 9 - only ever assume that. 10 - 11 - Fixes: https://bugs.freedesktop.org/105281 12 - --- 13 - include/bsd/libutil.h | 4 ++++ 14 - include/bsd/md5.h | 4 ++++ 15 - include/bsd/nlist.h | 4 ++++ 16 - include/bsd/readpassphrase.h | 4 ++++ 17 - include/bsd/stdlib.h | 4 ++++ 18 - include/bsd/string.h | 4 ++++ 19 - include/bsd/stringlist.h | 5 +++++ 20 - include/bsd/sys/queue.h | 4 ++++ 21 - include/bsd/sys/tree.h | 4 ++++ 22 - include/bsd/timeconv.h | 4 ++++ 23 - include/bsd/vis.h | 4 ++++ 24 - include/bsd/wchar.h | 4 ++++ 25 - 12 files changed, 49 insertions(+) 26 - 27 - diff --git a/include/bsd/libutil.h b/include/bsd/libutil.h 28 - index 45b3b15..ccca29a 100644 29 - --- a/include/bsd/libutil.h 30 - +++ b/include/bsd/libutil.h 31 - @@ -40,7 +40,11 @@ 32 - #define LIBBSD_LIBUTIL_H 33 - 34 - #include <features.h> 35 - +#ifdef LIBBSD_OVERLAY 36 - #include <sys/cdefs.h> 37 - +#else 38 - +#include <bsd/sys/cdefs.h> 39 - +#endif 40 - #include <sys/types.h> 41 - #include <stdint.h> 42 - #include <stdio.h> 43 - diff --git a/include/bsd/md5.h b/include/bsd/md5.h 44 - index 5f3ae46..bf36a30 100644 45 - --- a/include/bsd/md5.h 46 - +++ b/include/bsd/md5.h 47 - @@ -27,7 +27,11 @@ typedef struct MD5Context { 48 - uint8_t buffer[MD5_BLOCK_LENGTH]; /* input buffer */ 49 - } MD5_CTX; 50 - 51 - +#ifdef LIBBSD_OVERLAY 52 - #include <sys/cdefs.h> 53 - +#else 54 - +#include <bsd/sys/cdefs.h> 55 - +#endif 56 - #include <sys/types.h> 57 - 58 - __BEGIN_DECLS 59 - diff --git a/include/bsd/nlist.h b/include/bsd/nlist.h 60 - index cb297e8..8767117 100644 61 - --- a/include/bsd/nlist.h 62 - +++ b/include/bsd/nlist.h 63 - @@ -27,7 +27,11 @@ 64 - #ifndef LIBBSD_NLIST_H 65 - #define LIBBSD_NLIST_H 66 - 67 - +#ifdef LIBBSD_OVERLAY 68 - #include <sys/cdefs.h> 69 - +#else 70 - +#include <bsd/sys/cdefs.h> 71 - +#endif 72 - 73 - struct nlist { 74 - union { 75 - diff --git a/include/bsd/readpassphrase.h b/include/bsd/readpassphrase.h 76 - index 14744b8..5eb8021 100644 77 - --- a/include/bsd/readpassphrase.h 78 - +++ b/include/bsd/readpassphrase.h 79 - @@ -31,7 +31,11 @@ 80 - #define RPP_SEVENBIT 0x10 /* Strip the high bit from input. */ 81 - #define RPP_STDIN 0x20 /* Read from stdin, not /dev/tty */ 82 - 83 - +#ifdef LIBBSD_OVERLAY 84 - #include <sys/cdefs.h> 85 - +#else 86 - +#include <bsd/sys/cdefs.h> 87 - +#endif 88 - #include <sys/types.h> 89 - 90 - __BEGIN_DECLS 91 - diff --git a/include/bsd/stdlib.h b/include/bsd/stdlib.h 92 - index ebc9638..8d33d1f 100644 93 - --- a/include/bsd/stdlib.h 94 - +++ b/include/bsd/stdlib.h 95 - @@ -42,7 +42,11 @@ 96 - #ifndef LIBBSD_STDLIB_H 97 - #define LIBBSD_STDLIB_H 98 - 99 - +#ifdef LIBBSD_OVERLAY 100 - #include <sys/cdefs.h> 101 - +#else 102 - +#include <bsd/sys/cdefs.h> 103 - +#endif 104 - #include <sys/stat.h> 105 - #include <stdint.h> 106 - 107 - diff --git a/include/bsd/string.h b/include/bsd/string.h 108 - index 6798bf6..29097f6 100644 109 - --- a/include/bsd/string.h 110 - +++ b/include/bsd/string.h 111 - @@ -33,7 +33,11 @@ 112 - #ifndef LIBBSD_STRING_H 113 - #define LIBBSD_STRING_H 114 - 115 - +#ifdef LIBBSD_OVERLAY 116 - #include <sys/cdefs.h> 117 - +#else 118 - +#include <bsd/sys/cdefs.h> 119 - +#endif 120 - #include <sys/types.h> 121 - 122 - __BEGIN_DECLS 123 - diff --git a/include/bsd/stringlist.h b/include/bsd/stringlist.h 124 - index ff30cac..dd71496 100644 125 - --- a/include/bsd/stringlist.h 126 - +++ b/include/bsd/stringlist.h 127 - @@ -31,7 +31,12 @@ 128 - 129 - #ifndef LIBBSD_STRINGLIST_H 130 - #define LIBBSD_STRINGLIST_H 131 - + 132 - +#ifdef LIBBSD_OVERLAY 133 - #include <sys/cdefs.h> 134 - +#else 135 - +#include <bsd/sys/cdefs.h> 136 - +#endif 137 - #include <sys/types.h> 138 - 139 - /* 140 - diff --git a/include/bsd/sys/queue.h b/include/bsd/sys/queue.h 141 - index 4a94ea7..ac00026 100644 142 - --- a/include/bsd/sys/queue.h 143 - +++ b/include/bsd/sys/queue.h 144 - @@ -33,7 +33,11 @@ 145 - #ifndef LIBBSD_SYS_QUEUE_H 146 - #define LIBBSD_SYS_QUEUE_H 147 - 148 - +#ifdef LIBBSD_OVERLAY 149 - #include <sys/cdefs.h> 150 - +#else 151 - +#include <bsd/sys/cdefs.h> 152 - +#endif 153 - 154 - /* 155 - * This file defines four types of data structures: singly-linked lists, 156 - diff --git a/include/bsd/sys/tree.h b/include/bsd/sys/tree.h 157 - index 628bec0..325b382 100644 158 - --- a/include/bsd/sys/tree.h 159 - +++ b/include/bsd/sys/tree.h 160 - @@ -30,7 +30,11 @@ 161 - #ifndef LIBBSD_SYS_TREE_H 162 - #define LIBBSD_SYS_TREE_H 163 - 164 - +#ifdef LIBBSD_OVERLAY 165 - #include <sys/cdefs.h> 166 - +#else 167 - +#include <bsd/sys/cdefs.h> 168 - +#endif 169 - 170 - /* 171 - * This file defines data structures for different types of trees: 172 - diff --git a/include/bsd/timeconv.h b/include/bsd/timeconv.h 173 - index e2a2c55..a426bd3 100644 174 - --- a/include/bsd/timeconv.h 175 - +++ b/include/bsd/timeconv.h 176 - @@ -41,7 +41,11 @@ 177 - #ifndef LIBBSD_TIMECONV_H 178 - #define LIBBSD_TIMECONV_H 179 - 180 - +#ifdef LIBBSD_OVERLAY 181 - #include <sys/cdefs.h> 182 - +#else 183 - +#include <bsd/sys/cdefs.h> 184 - +#endif 185 - #include <stdint.h> 186 - #include <time.h> 187 - 188 - diff --git a/include/bsd/vis.h b/include/bsd/vis.h 189 - index 970dfdd..ab5430c 100644 190 - --- a/include/bsd/vis.h 191 - +++ b/include/bsd/vis.h 192 - @@ -72,7 +72,11 @@ 193 - */ 194 - #define UNVIS_END 1 /* no more characters */ 195 - 196 - +#ifdef LIBBSD_OVERLAY 197 - #include <sys/cdefs.h> 198 - +#else 199 - +#include <bsd/sys/cdefs.h> 200 - +#endif 201 - 202 - __BEGIN_DECLS 203 - char *vis(char *, int, int, int); 204 - diff --git a/include/bsd/wchar.h b/include/bsd/wchar.h 205 - index 33a500e..7216503 100644 206 - --- a/include/bsd/wchar.h 207 - +++ b/include/bsd/wchar.h 208 - @@ -40,7 +40,11 @@ 209 - #define LIBBSD_WCHAR_H 210 - 211 - #include <stddef.h> 212 - +#ifdef LIBBSD_OVERLAY 213 - #include <sys/cdefs.h> 214 - +#else 215 - +#include <bsd/sys/cdefs.h> 216 - +#endif 217 - #include <sys/types.h> 218 - 219 - __BEGIN_DECLS 220 - -- 221 - cgit v1.1 222 -
···
+205 -547
pkgs/development/libraries/libbsd/darwin.patch
··· 1 diff --git a/configure.ac b/configure.ac 2 - index 88ccd91..0857782 100644 3 --- a/configure.ac 4 +++ b/configure.ac 5 - @@ -59,7 +59,7 @@ AS_CASE([$host_os], 6 - ) 7 8 # Checks for header files. 9 -AC_CHECK_HEADERS([sys/ndir.h sys/dir.h ndir.h dirent.h]) 10 - +AC_CHECK_HEADERS([sys/ndir.h sys/dir.h ndir.h dirent.h stdio_ext.h]) 11 12 # Checks for typedefs, structures, and compiler characteristics. 13 AC_C_INLINE 14 - @@ -146,6 +146,31 @@ AC_CHECK_FUNCS([clearenv dirfd fopencookie __fpurge \ 15 - pstat_getproc sysconf]) 16 AM_CONDITIONAL([HAVE_GETENTROPY], [test "x$ac_cv_func_getentropy" = "xtrue"]) 17 18 - +HostOS=`echo "$host" | sed 's/.*-//'` 19 - +os_is_macosx=false 20 - +nonLinuxOS=false 21 - +AC_SUBST(HostOS) 22 - +case ${HostOS} in 23 - + darwin* | powerpc*-*-darwin* | freebsd* | netbsd* | openbsd*) 24 - + os_is_macosx=true 25 - + nonLinuxOS=true 26 - + echo HostOS="$HostOS" 27 - + ;; 28 - + *) 29 - + echo host="$host" 30 - + echo HostOS="$HostOS" 31 - + os_is_macosx=false 32 - + nonLinuxOS=false 33 - + ;; 34 - +esac 35 - +AM_CONDITIONAL([IS_DARWIN], [test x$os_is_macosx = xtrue]) 36 - +AM_COND_IF([IS_DARWIN], 37 - + [AC_DEFINE([IS_DARWIN], [1], [Get HostOS Type is Darwin])]) 38 - + 39 - +AM_CONDITIONAL([NON_LINUX], [test x$userdefine_gethostbyname_r = xtrue]) 40 - +AM_COND_IF([NON_LINUX], 41 - + [AC_DEFINE([NON_LINUX], [1], [Get HostOS Type])]) 42 - + 43 AC_CONFIG_FILES([ 44 - Makefile 45 - include/Makefile 46 - diff --git a/include/bsd/libutil.h b/include/bsd/libutil.h 47 - index 45b3b15..d0d4043 100644 48 - --- a/include/bsd/libutil.h 49 - +++ b/include/bsd/libutil.h 50 - @@ -39,7 +39,9 @@ 51 - #ifndef LIBBSD_LIBUTIL_H 52 - #define LIBBSD_LIBUTIL_H 53 - 54 - +#ifdef HAVE_FEATURES_H 55 - #include <features.h> 56 - +#endif 57 - #include <sys/cdefs.h> 58 - #include <sys/types.h> 59 - #include <stdint.h> 60 - diff --git a/include/bsd/stdio.h b/include/bsd/stdio.h 61 - index 4b69983..c75151b 100644 62 - --- a/include/bsd/stdio.h 63 - +++ b/include/bsd/stdio.h 64 - @@ -48,12 +48,16 @@ 65 - __BEGIN_DECLS 66 - const char *fmtcheck(const char *, const char *); 67 - 68 - +#if !defined(darwin) && !defined(__APPLE__) && !defined(MACOSX) 69 - /* XXX: The function requires cooperation from the system libc to store the 70 - * line buffer in the FILE struct itself. */ 71 - char *fgetln(FILE *fp, size_t *lenp) 72 - - LIBBSD_DEPRECATED("This functions cannot be safely ported, " 73 - - "use getline(3) instead, as it is supported " 74 - - "by GNU and POSIX.1-2008."); 75 - + __attribute__((deprecated("This functions cannot be safely ported, " 76 - + "use getline(3) instead, as it is supported " 77 - + "by GNU and POSIX.1-2008."))); 78 - +#else 79 - +char *fgetln(FILE *fp, size_t *lenp); 80 - +#endif 81 - 82 - /* 83 - * Note: We diverge from the FreeBSD, OpenBSD and DragonFlyBSD declarations, 84 - diff --git a/include/bsd/stdlib.h b/include/bsd/stdlib.h 85 - index ebc9638..6cd7943 100644 86 - --- a/include/bsd/stdlib.h 87 - +++ b/include/bsd/stdlib.h 88 - @@ -67,9 +67,11 @@ int sradixsort(const unsigned char **base, int nmemb, 89 - const unsigned char *table, unsigned endbyte); 90 - 91 - void *reallocf(void *ptr, size_t size); 92 - -#if defined(_GNU_SOURCE) && defined(__GLIBC__) && !__GLIBC_PREREQ(2, 26) 93 - +#if defined(_GNU_SOURCE) && defined(__GLIBC__) && defined(__GLIBC_PREREQ) 94 - +#if !__GLIBC_PREREQ(2, 26) 95 - void *reallocarray(void *ptr, size_t nmemb, size_t size); 96 - #endif 97 - +#endif 98 - 99 - long long strtonum(const char *nptr, long long minval, long long maxval, 100 - const char **errstr); 101 diff --git a/include/bsd/string.h b/include/bsd/string.h 102 - index 6798bf6..6baaa14 100644 103 --- a/include/bsd/string.h 104 +++ b/include/bsd/string.h 105 - @@ -37,6 +37,12 @@ 106 #include <sys/types.h> 107 108 __BEGIN_DECLS 109 - +#if defined(darwin) || defined(__APPLE__) || defined(MACOSX) 110 - +size_t bsd_strlcpy(char *dst, const char *src, size_t siz); 111 - +size_t bsd_strlcat(char *dst, const char *src, size_t siz); 112 - +char *bsd_strnstr(const char *str, const char *find, size_t str_len); 113 - +void bsd_strmode(mode_t mode, char *str); 114 - +#else 115 size_t strlcpy(char *dst, const char *src, size_t siz); 116 size_t strlcat(char *dst, const char *src, size_t siz); 117 char *strnstr(const char *str, const char *find, size_t str_len); 118 - @@ -45,6 +51,7 @@ void strmode(mode_t mode, char *str); 119 - #if defined(_GNU_SOURCE) && defined(__GLIBC__) && !__GLIBC_PREREQ(2, 25) 120 - void explicit_bzero(void *buf, size_t len); 121 - #endif 122 +#endif 123 - __END_DECLS 124 125 - #endif 126 diff --git a/src/Makefile.am b/src/Makefile.am 127 - index ad83dbf..0f2a7ee 100644 128 --- a/src/Makefile.am 129 +++ b/src/Makefile.am 130 - @@ -54,17 +54,21 @@ libbsd_la_DEPENDENCIES = \ 131 - libbsd.map 132 libbsd_la_LIBADD = \ 133 $(CLOCK_GETTIME_LIBS) 134 - + 135 - +if IS_DARWIN 136 - +libbsd_la_LDFLAGS = \ 137 - + -Wl \ 138 - + -version-number $(LIBBSD_ABI) 139 - +else 140 libbsd_la_LDFLAGS = \ 141 - -Wl,--version-script=$(srcdir)/libbsd.map \ 142 -version-number $(LIBBSD_ABI) 143 +endif 144 - + 145 libbsd_la_SOURCES = \ 146 arc4random.c \ 147 - - arc4random.h \ 148 - - arc4random_unix.h \ 149 - - arc4random_openbsd.h \ 150 - arc4random_uniform.c \ 151 - bsd_getopt.c \ 152 - - chacha_private.h \ 153 - closefrom.c \ 154 - dehumanize_number.c \ 155 - err.c \ 156 - @@ -117,6 +121,15 @@ libbsd_la_SOURCES += \ 157 - $(nil) 158 - endif 159 - 160 - +noinst_HEADERS = \ 161 - + arc4random.h \ 162 - + arc4random_bsd.h \ 163 - + arc4random_linux.h \ 164 - + arc4random_unix.h \ 165 - + arc4random_osx.h \ 166 - + arc4random_openbsd.h \ 167 - + chacha_private.h 168 - + 169 - libbsd_ctor_a_SOURCES = \ 170 - setproctitle_ctor.c \ 171 - $(nil) 172 - diff --git a/src/arc4random_bsd.h b/src/arc4random_bsd.h 173 - new file mode 100644 174 - index 0000000..ece2f85 175 - --- /dev/null 176 - +++ b/src/arc4random_bsd.h 177 - @@ -0,0 +1,86 @@ 178 - +/* $OpenBSD: arc4random_freebsd.h,v 1.2 2015/01/15 06:57:18 deraadt Exp $ */ 179 - + 180 - +/* 181 - + * Copyright (c) 1996, David Mazieres <dm@uun.org> 182 - + * Copyright (c) 2008, Damien Miller <djm@openbsd.org> 183 - + * Copyright (c) 2013, Markus Friedl <markus@openbsd.org> 184 - + * Copyright (c) 2014, Theo de Raadt <deraadt@openbsd.org> 185 - + * 186 - + * Permission to use, copy, modify, and distribute this software for any 187 - + * purpose with or without fee is hereby granted, provided that the above 188 - + * copyright notice and this permission notice appear in all copies. 189 - + * 190 - + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 191 - + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 192 - + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 193 - + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 194 - + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 195 - + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 196 - + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 197 - + */ 198 - + 199 - +/* 200 - + * Stub functions for portability. 201 - + */ 202 - + 203 - +#include <sys/mman.h> 204 - + 205 - +#include <pthread.h> 206 - +#include <signal.h> 207 - + 208 - +static pthread_mutex_t arc4random_mtx = PTHREAD_MUTEX_INITIALIZER; 209 - +#define _ARC4_LOCK() pthread_mutex_lock(&arc4random_mtx) 210 - +#define _ARC4_UNLOCK() pthread_mutex_unlock(&arc4random_mtx) 211 - + 212 - +/* 213 - + * Unfortunately, pthread_atfork() is broken on FreeBSD (at least 9 and 10) if 214 - + * a program does not link to -lthr. Callbacks registered with pthread_atfork() 215 - + * appear to fail silently. So, it is not always possible to detect a PID 216 - + * wraparound. 217 - + */ 218 - +#define _ARC4_ATFORK(f) pthread_atfork(NULL, NULL, (f)) 219 - + 220 - +static inline void 221 - +_getentropy_fail(void) 222 - +{ 223 - + raise(SIGKILL); 224 - +} 225 - + 226 - +static volatile sig_atomic_t _rs_forked; 227 - + 228 - +static inline void 229 - +_rs_forkhandler(void) 230 - +{ 231 - + _rs_forked = 1; 232 - +} 233 - + 234 - +static inline void 235 - +_rs_forkdetect(void) 236 - +{ 237 - + static pid_t _rs_pid = 0; 238 - + pid_t pid = getpid(); 239 - + 240 - + if (_rs_pid == 0 || _rs_pid != pid || _rs_forked) { 241 - + _rs_pid = pid; 242 - + _rs_forked = 0; 243 - + if (rs) 244 - + memset(rs, 0, sizeof(*rs)); 245 - + } 246 - +} 247 - + 248 - +static inline int 249 - +_rs_allocate(struct _rs **rsp, struct _rsx **rsxp) 250 - +{ 251 - + if ((*rsp = mmap(NULL, sizeof(**rsp), PROT_READ|PROT_WRITE, 252 - + MAP_ANON|MAP_PRIVATE, -1, 0)) == MAP_FAILED) 253 - + return (-1); 254 - + 255 - + if ((*rsxp = mmap(NULL, sizeof(**rsxp), PROT_READ|PROT_WRITE, 256 - + MAP_ANON|MAP_PRIVATE, -1, 0)) == MAP_FAILED) { 257 - + munmap(*rsp, sizeof(**rsp)); 258 - + return (-1); 259 - + } 260 - + 261 - + _ARC4_ATFORK(_rs_forkhandler); 262 - + return (0); 263 - +} 264 - diff --git a/src/arc4random_linux.h b/src/arc4random_linux.h 265 - new file mode 100644 266 - index 0000000..d61a8db 267 - --- /dev/null 268 - +++ b/src/arc4random_linux.h 269 - @@ -0,0 +1,86 @@ 270 - +/* $OpenBSD: arc4random_linux.h,v 1.8 2014/08/13 06:04:10 deraadt Exp $ */ 271 - + 272 - +/* 273 - + * Copyright (c) 1996, David Mazieres <dm@uun.org> 274 - + * Copyright (c) 2008, Damien Miller <djm@openbsd.org> 275 - + * Copyright (c) 2013, Markus Friedl <markus@openbsd.org> 276 - + * Copyright (c) 2014, Theo de Raadt <deraadt@openbsd.org> 277 - + * 278 - + * Permission to use, copy, modify, and distribute this software for any 279 - + * purpose with or without fee is hereby granted, provided that the above 280 - + * copyright notice and this permission notice appear in all copies. 281 - + * 282 - + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 283 - + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 284 - + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 285 - + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 286 - + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 287 - + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 288 - + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 289 - + */ 290 - + 291 - +/* 292 - + * Stub functions for portability. 293 - + */ 294 - + 295 - +#include <sys/mman.h> 296 - + 297 - +#include <pthread.h> 298 - +#include <signal.h> 299 - + 300 - +static pthread_mutex_t arc4random_mtx = PTHREAD_MUTEX_INITIALIZER; 301 - +#define _ARC4_LOCK() pthread_mutex_lock(&arc4random_mtx) 302 - +#define _ARC4_UNLOCK() pthread_mutex_unlock(&arc4random_mtx) 303 - + 304 - +#ifdef __GLIBC__ 305 - +extern void *__dso_handle; 306 - +extern int __register_atfork(void (*)(void), void(*)(void), void (*)(void), void *); 307 - +#define _ARC4_ATFORK(f) __register_atfork(NULL, NULL, (f), __dso_handle) 308 - +#else 309 - +#define _ARC4_ATFORK(f) pthread_atfork(NULL, NULL, (f)) 310 - +#endif 311 - + 312 - +static inline void 313 - +_getentropy_fail(void) 314 - +{ 315 - + raise(SIGKILL); 316 - +} 317 - + 318 - +static volatile sig_atomic_t _rs_forked; 319 - + 320 - +static inline void 321 - +_rs_forkhandler(void) 322 - +{ 323 - + _rs_forked = 1; 324 - +} 325 - + 326 - +static inline void 327 - +_rs_forkdetect(void) 328 - +{ 329 - + static pid_t _rs_pid = 0; 330 - + pid_t pid = getpid(); 331 - + 332 - + if (_rs_pid == 0 || _rs_pid != pid || _rs_forked) { 333 - + _rs_pid = pid; 334 - + _rs_forked = 0; 335 - + if (rs) 336 - + memset(rs, 0, sizeof(*rs)); 337 - + } 338 - +} 339 - + 340 - +static inline int 341 - +_rs_allocate(struct _rs **rsp, struct _rsx **rsxp) 342 - +{ 343 - + if ((*rsp = mmap(NULL, sizeof(**rsp), PROT_READ|PROT_WRITE, 344 - + MAP_ANON|MAP_PRIVATE, -1, 0)) == MAP_FAILED) 345 - + return (-1); 346 - + 347 - + if ((*rsxp = mmap(NULL, sizeof(**rsxp), PROT_READ|PROT_WRITE, 348 - + MAP_ANON|MAP_PRIVATE, -1, 0)) == MAP_FAILED) { 349 - + munmap(*rsp, sizeof(**rsp)); 350 - + return (-1); 351 - + } 352 - + 353 - + _ARC4_ATFORK(_rs_forkhandler); 354 - + return (0); 355 - +} 356 - diff --git a/src/arc4random_osx.h b/src/arc4random_osx.h 357 - new file mode 100644 358 - index 0000000..14771a6 359 - --- /dev/null 360 - +++ b/src/arc4random_osx.h 361 - @@ -0,0 +1,82 @@ 362 - +/* $OpenBSD: arc4random_osx.h,v 1.10 2015/09/11 11:52:55 deraadt Exp $ */ 363 - + 364 - +/* 365 - + * Copyright (c) 1996, David Mazieres <dm@uun.org> 366 - + * Copyright (c) 2008, Damien Miller <djm@openbsd.org> 367 - + * Copyright (c) 2013, Markus Friedl <markus@openbsd.org> 368 - + * Copyright (c) 2014, Theo de Raadt <deraadt@openbsd.org> 369 - + * 370 - + * Permission to use, copy, modify, and distribute this software for any 371 - + * purpose with or without fee is hereby granted, provided that the above 372 - + * copyright notice and this permission notice appear in all copies. 373 - + * 374 - + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 375 - + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 376 - + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 377 - + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 378 - + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 379 - + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 380 - + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 381 - + */ 382 - + 383 - +/* 384 - + * Stub functions for portability. 385 - + */ 386 - + 387 - +#include <sys/mman.h> 388 - + 389 - +#include <unistd.h> 390 - +#include <pthread.h> 391 - +#include <signal.h> 392 - + 393 - +static pthread_mutex_t arc4random_mtx = PTHREAD_MUTEX_INITIALIZER; 394 - +#define _ARC4_LOCK() pthread_mutex_lock(&arc4random_mtx) 395 - +#define _ARC4_UNLOCK() pthread_mutex_unlock(&arc4random_mtx) 396 - + 397 - +#define _ARC4_ATFORK(f) pthread_atfork(NULL, NULL, (f)) 398 - + 399 - +static inline void 400 - +_getentropy_fail(void) 401 - +{ 402 - + raise(SIGKILL); 403 - +} 404 - + 405 - +static volatile sig_atomic_t _rs_forked; 406 - + 407 - +static inline void 408 - +_rs_forkhandler(void) 409 - +{ 410 - + _rs_forked = 1; 411 - +} 412 - + 413 - +static inline void 414 - +_rs_forkdetect(void) 415 - +{ 416 - + static pid_t _rs_pid = 0; 417 - + pid_t pid = getpid(); 418 - + 419 - + if (_rs_pid == 0 || _rs_pid != pid || _rs_forked) { 420 - + _rs_pid = pid; 421 - + _rs_forked = 0; 422 - + if (rs) 423 - + memset(rs, 0, sizeof(*rs)); 424 - + } 425 - +} 426 - + 427 - +static inline int 428 - +_rs_allocate(struct _rs **rsp, struct _rsx **rsxp) 429 - +{ 430 - + if ((*rsp = mmap(NULL, sizeof(**rsp), PROT_READ|PROT_WRITE, 431 - + MAP_ANON|MAP_PRIVATE, -1, 0)) == MAP_FAILED) 432 - + return (-1); 433 - + 434 - + if ((*rsxp = mmap(NULL, sizeof(**rsxp), PROT_READ|PROT_WRITE, 435 - + MAP_ANON|MAP_PRIVATE, -1, 0)) == MAP_FAILED) { 436 - + munmap(*rsp, sizeof(**rsp)); 437 - + *rsp = NULL; 438 - + return (-1); 439 - + } 440 - + 441 - + _ARC4_ATFORK(_rs_forkhandler); 442 - + return (0); 443 - +} 444 - diff --git a/src/fgetln.c b/src/fgetln.c 445 - index 4d1726e..9c73788 100644 446 - --- a/src/fgetln.c 447 - +++ b/src/fgetln.c 448 - @@ -30,7 +30,9 @@ 449 - #include <sys/types.h> 450 - #include <string.h> 451 - 452 - +#if !defined(darwin) && !defined(__APPLE__) && !defined(MACOSX) 453 - #include "local-link.h" 454 - +#endif 455 - 456 - #ifdef HAVE_GETLINE 457 - struct filebuf { 458 - @@ -75,9 +77,11 @@ fgetln(FILE *stream, size_t *len) 459 - return fb->buf; 460 - } 461 - } 462 - +#if !defined(darwin) && !defined(__APPLE__) && !defined(MACOSX) 463 - libbsd_link_warning(fgetln, 464 - "This functions cannot be safely ported, use getline(3) " 465 - "instead, as it is supported by GNU and POSIX.1-2008.") 466 - +#endif 467 - #else 468 - #error "Function fgetln() needs to be ported." 469 - #endif 470 diff --git a/src/fpurge.c b/src/fpurge.c 471 - index 462535a..e7eb46f 100644 472 --- a/src/fpurge.c 473 +++ b/src/fpurge.c 474 - @@ -26,9 +26,11 @@ 475 476 #include <errno.h> 477 #include <stdio.h> 478 - +#if HAVE___FPURGE 479 - #include <stdio_ext.h> 480 - +#endif 481 482 - -#ifdef HAVE___FPURGE 483 - +#ifdef HAVE___FPURGE /* glibc >= 2.2, Haiku, Solaris >= 7 */ 484 int 485 fpurge(FILE *fp) 486 { 487 - @@ -42,5 +44,55 @@ fpurge(FILE *fp) 488 return 0; 489 } 490 - #else 491 - -#error "Function fpurge() needs to be ported." 492 - +#define fp_ fp 493 - +//#error "Function fpurge() needs to be ported." 494 - +//#elif HAVE_FPURGE /* FreeBSD, NetBSD, OpenBSD, DragonFly, Mac OS X, Cygwin 1.7 */ 495 +int 496 +fpurge(FILE *fp) 497 +{ ··· 501 + } 502 + 503 + /* Call the system's fpurge function. */ 504 - +# undef fpurge 505 - +# if !HAVE_DECL_FPURGE 506 + extern int fpurge (FILE *); 507 - +# endif 508 + int result = fpurge (fp); 509 - +# if defined __sferror || defined __DragonFly__ /* FreeBSD, NetBSD, OpenBSD, DragonFly, Mac OS X, Cygwin */ 510 + if (result == 0) 511 + /* Correct the invariants that fpurge broke. 512 + <stdio.h> on BSD systems says: ··· 514 + If this invariant is not fulfilled and the stream is read-write but 515 + currently reading, subsequent putc or fputc calls will write directly 516 + into the buffer, although they shouldn't be allowed to. */ 517 - + if ((fp_->_flags & __SRD) != 0) 518 - + fp_->_w = 0; 519 +#endif 520 + return result; 521 +} 522 - +//#endif 523 - +#endif 524 - + 525 - +#ifdef TEST 526 - +int 527 - +main() 528 - +{ 529 - + static FILE fp_bad; 530 - + FILE *fp; 531 - + 532 - + if (fpurge(&fp_bad) == 0) 533 - + return 1; 534 - + 535 - + fp = fopen("/dev/zero", "r"); 536 - + if (fpurge(fp) < 0) 537 - + return 1; 538 - + 539 - + fclose(fp); 540 - + 541 - + return 0; 542 - +} 543 #endif 544 diff --git a/src/funopen.c b/src/funopen.c 545 - index 1e05c7e..75e61ea 100644 546 --- a/src/funopen.c 547 +++ b/src/funopen.c 548 @@ -143,6 +143,7 @@ funopen(const void *cookie, 549 * they will not add the needed support to implement it. Just ignore this 550 * interface there, as it has never been provided anyway. 551 */ 552 - +#elif defined(darwin) || defined(__APPLE__) || defined(MACOSX) 553 #else 554 #error "Function funopen() needs to be ported or disabled." 555 #endif 556 - diff --git a/src/getentropy.c b/src/getentropy.c 557 - index 3f11a1e..8a23a07 100644 558 - --- a/src/getentropy.c 559 - +++ b/src/getentropy.c 560 - @@ -28,9 +28,7 @@ 561 - #include "getentropy_linux.c" 562 - #elif defined(__GNU__) 563 - #include "getentropy_hurd.c" 564 - -#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) 565 - -#include "getentropy_bsd.c" 566 - -#elif defined(__NetBSD__) 567 - +#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__NetBSD__) 568 - #include "getentropy_bsd.c" 569 - #elif defined(__sun) 570 - #include "getentropy_solaris.c" 571 diff --git a/src/hash/sha512.h b/src/hash/sha512.h 572 - index 4f368a1..ab22fc1 100644 573 --- a/src/hash/sha512.h 574 +++ b/src/hash/sha512.h 575 @@ -29,7 +29,11 @@ 576 #ifndef _SHA512_H_ 577 #define _SHA512_H_ 578 579 - +#if defined(darwin) || defined(__APPLE__) || defined(MACOSX) 580 +#include <stdint.h> 581 +#else 582 #include <sys/types.h> ··· 585 #define SHA512_DIGEST_LENGTH 64 586 587 diff --git a/src/hash/sha512c.c b/src/hash/sha512c.c 588 - index b3c8d5e..f69013d 100644 589 --- a/src/hash/sha512c.c 590 +++ b/src/hash/sha512c.c 591 - @@ -25,7 +25,13 @@ 592 */ 593 594 #include <sys/cdefs.h> 595 - +__FBSDID("$FreeBSD$"); 596 + 597 - +#if defined(darwin) || defined(__APPLE__) || defined(MACOSX) 598 +#include <machine/endian.h> 599 +#else 600 #include <sys/endian.h> ··· 602 #include <sys/types.h> 603 604 #include <string.h> 605 diff --git a/src/nlist.c b/src/nlist.c 606 - index 0932f59..598a329 100644 607 --- a/src/nlist.c 608 +++ b/src/nlist.c 609 - @@ -27,6 +27,10 @@ 610 - * SUCH DAMAGE. 611 - */ 612 613 - +#if !defined(darwin) && !defined(__APPLE__) && !defined(MACOSX) 614 - +#if defined(LIBC_SCCS) && !defined(lint) 615 - +static char sccsid[] = "@(#)nlist.c 8.1 (Berkeley) 6/4/93"; 616 - +#endif /* LIBC_SCCS and not lint */ 617 - #include <sys/cdefs.h> 618 619 - #include <sys/param.h> 620 - @@ -265,3 +269,4 @@ nlist(const char *name, struct nlist *list) 621 (void)close(fd); 622 return (n); 623 } 624 - +#endif /* _NLIST_DO_ELF */ 625 diff --git a/src/setproctitle.c b/src/setproctitle.c 626 - index 038ac7d..d0ef01b 100644 627 --- a/src/setproctitle.c 628 +++ b/src/setproctitle.c 629 - @@ -32,6 +32,11 @@ 630 #include <unistd.h> 631 #include <string.h> 632 633 - +#if defined(darwin) || defined(__APPLE__) || defined(MACOSX) 634 - +#define __asm__(x) 635 +extern char **environ; 636 +#endif 637 + 638 static struct { 639 /* Original value. */ 640 const char *arg0; 641 - @@ -287,7 +292,14 @@ __asm__(".symver setproctitle_impl,setproctitle@@LIBBSD_0.5"); 642 * for code linking against that version, and change the default to use the 643 * new version, so that new code depends on the implemented version. */ 644 - #ifdef HAVE_TYPEOF 645 - +#if defined(darwin) || defined(__APPLE__) || defined(MACOSX) 646 - +// 647 - +// HACK: even weak aliasing breaks in clang so just comment this out for now 648 - +// 649 - +// extern typeof(setproctitle_impl) setproctitle_stub __attribute__((weak, alias("setproctitle_impl"))); 650 - +#else 651 extern typeof(setproctitle_impl) setproctitle_stub __attribute__((alias("setproctitle_impl"))); 652 - +#endif 653 #else 654 void setproctitle_stub(const char *fmt, ...) 655 __attribute__((alias("setproctitle_impl"))); 656 diff --git a/src/strlcat.c b/src/strlcat.c 657 - index 14c53a1..e01cb60 100644 658 --- a/src/strlcat.c 659 +++ b/src/strlcat.c 660 - @@ -27,7 +27,11 @@ 661 * If retval >= dsize, truncation occurred. 662 */ 663 size_t 664 - +#if defined(darwin) || defined(__APPLE__) || defined(MACOSX) 665 - +bsd_strlcat(char *dst, const char *src, size_t dsize) 666 - +#else 667 strlcat(char *dst, const char *src, size_t dsize) 668 - +#endif 669 { 670 - const char *odst = dst; 671 - const char *osrc = src; 672 diff --git a/src/strlcpy.c b/src/strlcpy.c 673 - index e9a7fe4..10a855f 100644 674 --- a/src/strlcpy.c 675 +++ b/src/strlcpy.c 676 - @@ -25,7 +25,11 @@ 677 * Returns strlen(src); if retval >= dsize, truncation occurred. 678 */ 679 size_t 680 - +#if defined(darwin) || defined(__APPLE__) || defined(MACOSX) 681 - +bsd_strlcpy(char *dst, const char *src, size_t dsize) 682 - +#else 683 strlcpy(char *dst, const char *src, size_t dsize) 684 - +#endif 685 { 686 - const char *osrc = src; 687 - size_t nleft = dsize; 688 diff --git a/src/strmode.c b/src/strmode.c 689 - index e6afde5..c463243 100644 690 --- a/src/strmode.c 691 +++ b/src/strmode.c 692 - @@ -33,7 +33,11 @@ 693 #include <string.h> 694 695 void 696 - +#if defined(darwin) || defined(__APPLE__) || defined(MACOSX) 697 - +bsd_strmode(mode_t mode, char *p) 698 - +#else 699 strmode(mode_t mode, char *p) 700 +#endif 701 { 702 - /* print type */ 703 - switch (mode & S_IFMT) {
··· 1 diff --git a/configure.ac b/configure.ac 2 + index 55fcfe6..1e26c93 100644 3 --- a/configure.ac 4 +++ b/configure.ac 5 + @@ -51,15 +51,19 @@ AS_CASE([$host_os], 6 + AC_SEARCH_LIBS([clock_gettime], [rt], [CLOCK_GETTIME_LIBS="-lrt"]) 7 + AC_SUBST([CLOCK_GETTIME_LIBS]) 8 + LIBS="$saved_LIBS" 9 + + AM_CONDITIONAL([BUILD_LINK_VERSION_SCRIPT], [1]) 10 + ], 11 + [*-musl*], [ 12 + # Upstream refuses to define this, we will do it ourselves then. 13 + AC_DEFINE([__MUSL__], [1], [Define to 1 if we are building for musl]) 14 + + AM_CONDITIONAL([BUILD_LINK_VERSION_SCRIPT], [1]) 15 + ], 16 + -) 17 + + [ 18 + + AM_CONDITIONAL([BUILD_LINK_VERSION_SCRIPT], [1]) 19 + + ]) 20 21 # Checks for header files. 22 -AC_CHECK_HEADERS([sys/ndir.h sys/dir.h ndir.h dirent.h]) 23 + +AC_CHECK_HEADERS([sys/ndir.h sys/dir.h ndir.h dirent.h nlist.h]) 24 25 # Checks for typedefs, structures, and compiler characteristics. 26 AC_C_INLINE 27 + @@ -143,7 +147,8 @@ AC_LINK_IFELSE( 28 + 29 + AC_CHECK_FUNCS([clearenv dirfd fopencookie __fpurge \ 30 + getauxval getentropy getexecname getline \ 31 + - pstat_getproc sysconf]) 32 + + pstat_getproc sysconf \ 33 + + strlcpy strlcat strnstr strmode fpurge]) 34 AM_CONDITIONAL([HAVE_GETENTROPY], [test "x$ac_cv_func_getentropy" = "xtrue"]) 35 36 AC_CONFIG_FILES([ 37 diff --git a/include/bsd/string.h b/include/bsd/string.h 38 + index f987fee..a1e17ed 100644 39 --- a/include/bsd/string.h 40 +++ b/include/bsd/string.h 41 + @@ -41,10 +41,21 @@ 42 #include <sys/types.h> 43 44 __BEGIN_DECLS 45 + +#if !HAVE_STRLCPY 46 size_t strlcpy(char *dst, const char *src, size_t siz); 47 + +#endif 48 + + 49 + +#if !HAVE_STRLCAT 50 size_t strlcat(char *dst, const char *src, size_t siz); 51 + +#endif 52 + + 53 + +#if !HAVE_STRNSTR 54 char *strnstr(const char *str, const char *find, size_t str_len); 55 + +#endif 56 + + 57 + +#if !HAVE_STRMODE 58 + void strmode(mode_t mode, char *str); 59 +#endif 60 61 + #if !defined(__GLIBC__) || \ 62 + (defined(__GLIBC__) && (!__GLIBC_PREREQ(2, 25) || !defined(_GNU_SOURCE))) 63 diff --git a/src/Makefile.am b/src/Makefile.am 64 + index f3cc0fa..3aaecd4 100644 65 --- a/src/Makefile.am 66 +++ b/src/Makefile.am 67 + @@ -56,8 +56,10 @@ libbsd_la_DEPENDENCIES = \ 68 libbsd_la_LIBADD = \ 69 $(CLOCK_GETTIME_LIBS) 70 libbsd_la_LDFLAGS = \ 71 + - -Wl,--version-script=$(srcdir)/libbsd.map \ 72 -version-number $(LIBBSD_ABI) 73 + +if BUILD_LINK_VERSION_SCRIPT 74 + +libbsd_la_LDFLAGS += -Wl,--version-script=$(srcdir)/libbsd.map 75 +endif 76 libbsd_la_SOURCES = \ 77 arc4random.c \ 78 + arc4random.h \ 79 diff --git a/src/fpurge.c b/src/fpurge.c 80 + index 462535a..a8941db 100644 81 --- a/src/fpurge.c 82 +++ b/src/fpurge.c 83 + @@ -26,9 +26,10 @@ 84 85 #include <errno.h> 86 #include <stdio.h> 87 + -#include <stdio_ext.h> 88 89 + #ifdef HAVE___FPURGE 90 + +#include <stdio_ext.h> 91 + + 92 int 93 fpurge(FILE *fp) 94 { 95 + @@ -41,6 +42,36 @@ fpurge(FILE *fp) 96 + 97 return 0; 98 } 99 + +/* FreeBSD, NetBSD, OpenBSD, DragonFly, Mac OS X, Cygwin 1.7 */ 100 + +#elif HAVE_FPURGE 101 +int 102 +fpurge(FILE *fp) 103 +{ ··· 107 + } 108 + 109 + /* Call the system's fpurge function. */ 110 + +#undef fpurge 111 + +#if !HAVE_DECL_FPURGE 112 + extern int fpurge (FILE *); 113 + +#endif 114 + int result = fpurge (fp); 115 + +/* FreeBSD, NetBSD, OpenBSD, DragonFly, Mac OS X, Cygwin */ 116 + +#if defined(__sferror) || defined(__DragonFly__) 117 + if (result == 0) 118 + /* Correct the invariants that fpurge broke. 119 + <stdio.h> on BSD systems says: ··· 121 + If this invariant is not fulfilled and the stream is read-write but 122 + currently reading, subsequent putc or fputc calls will write directly 123 + into the buffer, although they shouldn't be allowed to. */ 124 + + if ((fp->_flags & __SRD) != 0) 125 + + fp->_w = 0; 126 +#endif 127 + return result; 128 +} 129 + #else 130 + #error "Function fpurge() needs to be ported." 131 #endif 132 diff --git a/src/funopen.c b/src/funopen.c 133 + index 1e05c7e..65ba5a8 100644 134 --- a/src/funopen.c 135 +++ b/src/funopen.c 136 @@ -143,6 +143,7 @@ funopen(const void *cookie, 137 * they will not add the needed support to implement it. Just ignore this 138 * interface there, as it has never been provided anyway. 139 */ 140 + +#elif defined(__MACH__) 141 #else 142 #error "Function funopen() needs to be ported or disabled." 143 #endif 144 diff --git a/src/hash/sha512.h b/src/hash/sha512.h 145 + index 4f368a1..7632e25 100644 146 --- a/src/hash/sha512.h 147 +++ b/src/hash/sha512.h 148 @@ -29,7 +29,11 @@ 149 #ifndef _SHA512_H_ 150 #define _SHA512_H_ 151 152 + +#ifdef __MACH__ 153 +#include <stdint.h> 154 +#else 155 #include <sys/types.h> ··· 158 #define SHA512_DIGEST_LENGTH 64 159 160 diff --git a/src/hash/sha512c.c b/src/hash/sha512c.c 161 + index b3c8d5e..602f54e 100644 162 --- a/src/hash/sha512c.c 163 +++ b/src/hash/sha512c.c 164 + @@ -25,7 +25,12 @@ 165 */ 166 167 #include <sys/cdefs.h> 168 + 169 + +#ifdef __MACH__ 170 +#include <machine/endian.h> 171 +#else 172 #include <sys/endian.h> ··· 174 #include <sys/types.h> 175 176 #include <string.h> 177 + diff --git a/src/local-link.h b/src/local-link.h 178 + index d518dcf..84694a2 100644 179 + --- a/src/local-link.h 180 + +++ b/src/local-link.h 181 + @@ -27,7 +27,11 @@ 182 + #ifndef LIBBSD_LOCAL_LINK_H 183 + #define LIBBSD_LOCAL_LINK_H 184 + 185 + +#ifdef __MACH__ 186 + +#define libbsd_link_warning(symbol, msg) 187 + +#else 188 + #define libbsd_link_warning(symbol, msg) \ 189 + static const char libbsd_emit_link_warning_##symbol[] \ 190 + __attribute__((used,section(".gnu.warning." #symbol))) = msg; 191 + #endif 192 + +#endif 193 diff --git a/src/nlist.c b/src/nlist.c 194 + index 0932f59..4502048 100644 195 --- a/src/nlist.c 196 +++ b/src/nlist.c 197 + @@ -41,6 +41,7 @@ 198 + #include <unistd.h> 199 + #include <nlist.h> 200 201 + +#if !HAVE_NLIST_H 202 + #include "local-elf.h" 203 204 + #define SIZE_T_MAX 0xffffffffU 205 + @@ -265,3 +266,4 @@ nlist(const char *name, struct nlist *list) 206 (void)close(fd); 207 return (n); 208 } 209 + +#endif 210 + diff --git a/src/readpassphrase.c b/src/readpassphrase.c 211 + index f9f6195..2bc5fb4 100644 212 + --- a/src/readpassphrase.c 213 + +++ b/src/readpassphrase.c 214 + @@ -36,6 +36,14 @@ 215 + #define TCSASOFT 0 216 + #endif 217 + 218 + +#ifndef _SIGMAX 219 + +#define _SIGMAX 64 220 + +#endif 221 + + 222 + +#ifndef _NSIG 223 + +#define _NSIG (_SIGMAX + 1) 224 + +#endif 225 + + 226 + static volatile sig_atomic_t signo[_NSIG]; 227 + 228 + static void handler(int); 229 diff --git a/src/setproctitle.c b/src/setproctitle.c 230 + index 038ac7d..e9ee09c 100644 231 --- a/src/setproctitle.c 232 +++ b/src/setproctitle.c 233 + @@ -32,6 +32,10 @@ 234 #include <unistd.h> 235 #include <string.h> 236 237 + +#ifdef __MACH__ 238 +extern char **environ; 239 +#endif 240 + 241 static struct { 242 /* Original value. */ 243 const char *arg0; 244 + @@ -280,16 +284,22 @@ setproctitle_impl(const char *fmt, ...) 245 + *++nul = '\0'; 246 + } 247 + } 248 + +#ifndef __MACH__ 249 + __asm__(".symver setproctitle_impl,setproctitle@@LIBBSD_0.5"); 250 + +#endif 251 + 252 + /* The original function introduced in 0.2 was a stub, it only got implemented 253 + * in 0.5, make the implementation available in the old version as an alias 254 * for code linking against that version, and change the default to use the 255 * new version, so that new code depends on the implemented version. */ 256 + -#ifdef HAVE_TYPEOF 257 + +#ifdef __MACH__ 258 + +void setproctitle_stub(const char *fmt, ...); 259 + +#elif HAVE_TYPEOF 260 extern typeof(setproctitle_impl) setproctitle_stub __attribute__((alias("setproctitle_impl"))); 261 #else 262 void setproctitle_stub(const char *fmt, ...) 263 __attribute__((alias("setproctitle_impl"))); 264 + #endif 265 + +#ifndef __MACH__ 266 + __asm__(".symver setproctitle_stub,setproctitle@LIBBSD_0.2"); 267 + +#endif 268 diff --git a/src/strlcat.c b/src/strlcat.c 269 + index 14c53a1..5961c17 100644 270 --- a/src/strlcat.c 271 +++ b/src/strlcat.c 272 + @@ -26,6 +26,7 @@ 273 + * Returns strlen(src) + MIN(dsize, strlen(initial dst)). 274 * If retval >= dsize, truncation occurred. 275 */ 276 + +#if !HAVE_STRLCAT 277 size_t 278 strlcat(char *dst, const char *src, size_t dsize) 279 { 280 + @@ -53,3 +54,4 @@ strlcat(char *dst, const char *src, size_t dsize) 281 + 282 + return(dlen + (src - osrc)); /* count does not include NUL */ 283 + } 284 + +#endif 285 diff --git a/src/strlcpy.c b/src/strlcpy.c 286 + index e9a7fe4..5137acb 100644 287 --- a/src/strlcpy.c 288 +++ b/src/strlcpy.c 289 + @@ -24,6 +24,7 @@ 290 + * chars will be copied. Always NUL terminates (unless dsize == 0). 291 * Returns strlen(src); if retval >= dsize, truncation occurred. 292 */ 293 + +#if !HAVE_STRLCPY 294 size_t 295 strlcpy(char *dst, const char *src, size_t dsize) 296 { 297 + @@ -48,3 +49,4 @@ strlcpy(char *dst, const char *src, size_t dsize) 298 + 299 + return(src - osrc - 1); /* count does not include NUL */ 300 + } 301 + +#endif 302 diff --git a/src/strmode.c b/src/strmode.c 303 + index e6afde5..da680c9 100644 304 --- a/src/strmode.c 305 +++ b/src/strmode.c 306 + @@ -32,6 +32,7 @@ 307 + #include <sys/stat.h> 308 #include <string.h> 309 310 + +#if !HAVE_STRMODE 311 void 312 strmode(mode_t mode, char *p) 313 + { 314 + @@ -141,3 +142,4 @@ strmode(mode_t mode, char *p) 315 + *p++ = ' '; /* will be a '+' if ACL's implemented */ 316 + *p = '\0'; 317 + } 318 +#endif 319 + diff --git a/src/unvis.c b/src/unvis.c 320 + index 94e3e7a..fba4c66 100644 321 + --- a/src/unvis.c 322 + +++ b/src/unvis.c 323 + @@ -565,11 +565,15 @@ strnunvis_openbsd(char *dst, const char *src, size_t dlen) 324 { 325 + return strnunvisx(dst, dlen, src, 0); 326 + } 327 + +#ifndef __MACH__ 328 + __asm__(".symver strnunvis_openbsd,strnunvis@@LIBBSD_0.2"); 329 + +#endif 330 + 331 + int 332 + strnunvis_netbsd(char *dst, size_t dlen, const char *src) 333 + { 334 + return strnunvisx(dst, dlen, src, 0); 335 + } 336 + +#ifndef __MACH__ 337 + __asm__(".symver strnunvis_netbsd,strnunvis@LIBBSD_0.9.1"); 338 + +#endif 339 + diff --git a/src/vis.c b/src/vis.c 340 + index c2cd2d8..2d84330 100644 341 + --- a/src/vis.c 342 + +++ b/src/vis.c 343 + @@ -723,14 +723,18 @@ strnvis_openbsd(char *mbdst, const char *mbsrc, size_t dlen, int flags) 344 + { 345 + return istrsenvisxl(&mbdst, &dlen, mbsrc, flags, "", NULL); 346 + } 347 + +#ifndef __MACH__ 348 + __asm__(".symver strnvis_openbsd,strnvis@@LIBBSD_0.2"); 349 + +#endif 350 + 351 + int 352 + strnvis_netbsd(char *mbdst, size_t dlen, const char *mbsrc, int flags) 353 + { 354 + return istrsenvisxl(&mbdst, &dlen, mbsrc, flags, "", NULL); 355 + } 356 + +#ifndef __MACH__ 357 + __asm__(".symver strnvis_netbsd,strnvis@LIBBSD_0.9.1"); 358 + +#endif 359 + 360 + int 361 + stravis(char **mbdstp, const char *mbsrc, int flags)
+1 -10
pkgs/development/libraries/libbsd/default.nix
··· 13 # the configure scripts 14 nativeBuildInputs = [ autoreconfHook ]; 15 16 - patches = stdenv.lib.optional stdenv.isDarwin ./darwin.patch 17 - # Suitable for all, but limited to musl to avoid rebuilds 18 - ++ stdenv.lib.optionals stdenv.hostPlatform.isMusl [ 19 - # https://cgit.freedesktop.org/libbsd/commit/?id=1f8a3f7bccfc84b195218ad0086ebd57049c3490 20 - ./non-glibc.patch 21 - # https://cgit.freedesktop.org/libbsd/commit/?id=11ec8f1e5dfa1c10e0c9fb94879b6f5b96ba52dd 22 - ./cdefs.patch 23 - # https://cgit.freedesktop.org/libbsd/commit/?id=b20272f5a966333b49fdf2bda797e2a9f0227404 24 - ./features.patch 25 - ]; 26 27 meta = with stdenv.lib; { 28 description = "Common functions found on BSD systems";
··· 13 # the configure scripts 14 nativeBuildInputs = [ autoreconfHook ]; 15 16 + patches = stdenv.lib.optional stdenv.isDarwin ./darwin.patch; 17 18 meta = with stdenv.lib; { 19 description = "Common functions found on BSD systems";
-26
pkgs/development/libraries/libbsd/features.patch
··· 1 - From b20272f5a966333b49fdf2bda797e2a9f0227404 Mon Sep 17 00:00:00 2001 2 - From: Guillem Jover <guillem@hadrons.org> 3 - Date: Tue, 6 Mar 2018 01:42:52 +0100 4 - Subject: Remove <features.h> inclusion from <bsd/libutil.h> 5 - 6 - This is a non-portable header, and we should not assume it is present. 7 - Let the first system header pull it in if needed. 8 - --- 9 - include/bsd/libutil.h | 1 - 10 - 1 file changed, 1 deletion(-) 11 - 12 - diff --git a/include/bsd/libutil.h b/include/bsd/libutil.h 13 - index ccca29a..e5f148a 100644 14 - --- a/include/bsd/libutil.h 15 - +++ b/include/bsd/libutil.h 16 - @@ -39,7 +39,6 @@ 17 - #ifndef LIBBSD_LIBUTIL_H 18 - #define LIBBSD_LIBUTIL_H 19 - 20 - -#include <features.h> 21 - #ifdef LIBBSD_OVERLAY 22 - #include <sys/cdefs.h> 23 - #else 24 - -- 25 - cgit v1.1 26 -
···
-74
pkgs/development/libraries/libbsd/non-glibc.patch
··· 1 - From 1f8a3f7bccfc84b195218ad0086ebd57049c3490 Mon Sep 17 00:00:00 2001 2 - From: Guillem Jover <guillem@hadrons.org> 3 - Date: Tue, 6 Mar 2018 01:39:45 +0100 4 - Subject: Fix function declaration protection for glibc already providing them 5 - MIME-Version: 1.0 6 - Content-Type: text/plain; charset=UTF-8 7 - Content-Transfer-Encoding: 8bit 8 - 9 - On non-glibc based systems we cannot unconditionally use the 10 - __GLIBC_PREREQ macro as it gets expanded before evaluation. Instead, 11 - if it is undefined, define it to 0. 12 - 13 - We should also always declare these functions on non-glibc based 14 - systems. And on systems with a new enough glibc, which provides these 15 - functions, we should still provide the declarations if _GNU_SOURCE 16 - is *not* defined. 17 - 18 - Reported-by: Jörg Krause <joerg.krause@embedded.rocks> 19 - --- 20 - include/bsd/stdlib.h | 3 ++- 21 - include/bsd/string.h | 3 ++- 22 - include/bsd/sys/cdefs.h | 8 ++++++++ 23 - 3 files changed, 12 insertions(+), 2 deletions(-) 24 - 25 - diff --git a/include/bsd/stdlib.h b/include/bsd/stdlib.h 26 - index 8d33d1f..a5b063c 100644 27 - --- a/include/bsd/stdlib.h 28 - +++ b/include/bsd/stdlib.h 29 - @@ -71,7 +71,8 @@ int sradixsort(const unsigned char **base, int nmemb, 30 - const unsigned char *table, unsigned endbyte); 31 - 32 - void *reallocf(void *ptr, size_t size); 33 - -#if defined(_GNU_SOURCE) && defined(__GLIBC__) && !__GLIBC_PREREQ(2, 26) 34 - +#if !defined(__GLIBC__) || \ 35 - + (defined(__GLIBC__) && (!__GLIBC_PREREQ(2, 26) || !defined(_GNU_SOURCE))) 36 - void *reallocarray(void *ptr, size_t nmemb, size_t size); 37 - #endif 38 - 39 - diff --git a/include/bsd/string.h b/include/bsd/string.h 40 - index 29097f6..f987fee 100644 41 - --- a/include/bsd/string.h 42 - +++ b/include/bsd/string.h 43 - @@ -46,7 +46,8 @@ size_t strlcat(char *dst, const char *src, size_t siz); 44 - char *strnstr(const char *str, const char *find, size_t str_len); 45 - void strmode(mode_t mode, char *str); 46 - 47 - -#if defined(_GNU_SOURCE) && defined(__GLIBC__) && !__GLIBC_PREREQ(2, 25) 48 - +#if !defined(__GLIBC__) || \ 49 - + (defined(__GLIBC__) && (!__GLIBC_PREREQ(2, 25) || !defined(_GNU_SOURCE))) 50 - void explicit_bzero(void *buf, size_t len); 51 - #endif 52 - __END_DECLS 53 - diff --git a/include/bsd/sys/cdefs.h b/include/bsd/sys/cdefs.h 54 - index b4c8f30..d1cc419 100644 55 - --- a/include/bsd/sys/cdefs.h 56 - +++ b/include/bsd/sys/cdefs.h 57 - @@ -59,6 +59,14 @@ 58 - #endif 59 - 60 - /* 61 - + * On non-glibc based systems, we cannot unconditionally use the 62 - + * __GLIBC_PREREQ macro as it gets expanded before evaluation. 63 - + */ 64 - +#ifndef __GLIBC_PREREQ 65 - +#define __GLIBC_PREREQ(maj, min) 0 66 - +#endif 67 - + 68 - +/* 69 - * Some kFreeBSD headers expect those macros to be set for sanity checks. 70 - */ 71 - #ifndef _SYS_CDEFS_H_ 72 - -- 73 - cgit v1.1 74 -
···