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