tangled
alpha
login
or
join now
pyrox.dev
/
nixpkgs
0
fork
atom
lol
0
fork
atom
overview
issues
pulls
pipelines
libbsd: use patch instead of fork
Matthew Bauer
9 years ago
b6888270
8316eb5a
+684
-18
2 changed files
expand all
collapse all
unified
split
pkgs
development
libraries
libbsd
darwin.patch
default.nix
+675
pkgs/development/libraries/libbsd/darwin.patch
···
1
1
+
diff --git a/configure.ac b/configure.ac
2
2
+
index 5a432d4..a69ae0b 100644
3
3
+
--- a/configure.ac
4
4
+
+++ b/configure.ac
5
5
+
@@ -55,7 +55,7 @@ AS_CASE([$host_os],
6
6
+
)
7
7
+
8
8
+
# Checks for header files.
9
9
+
-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])
11
11
+
12
12
+
# Checks for typedefs, structures, and compiler characteristics.
13
13
+
AC_TYPE_UID_T
14
14
+
@@ -143,6 +143,31 @@ AC_CHECK_FUNCS([clearenv dirfd fopencookie __fpurge \
15
15
+
pstat_getproc sysconf])
16
16
+
AM_CONDITIONAL(HAVE_GETENTROPY, [test "x$ac_cv_func_getentropy" = "xtrue"])
17
17
+
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
43
+
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 ebb6160..ce882bf 100644
48
48
+
--- a/include/bsd/libutil.h
49
49
+
+++ b/include/bsd/libutil.h
50
50
+
@@ -39,7 +39,9 @@
51
51
+
#ifndef _LIBUTIL_H_
52
52
+
#define _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 7697425..ef34c4f 100644
62
62
+
--- a/include/bsd/stdio.h
63
63
+
+++ b/include/bsd/stdio.h
64
64
+
@@ -44,12 +44,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
+
__attribute__((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
+
+#else
76
76
+
+char *fgetln(FILE *fp, size_t *lenp);
77
77
+
+#endif
78
78
+
79
79
+
/*
80
80
+
* Note: We diverge from the FreeBSD, OpenBSD and DragonFlyBSD declarations,
81
81
+
diff --git a/include/bsd/string.h b/include/bsd/string.h
82
82
+
index ee2f953..a3ab077 100644
83
83
+
--- a/include/bsd/string.h
84
84
+
+++ b/include/bsd/string.h
85
85
+
@@ -37,11 +37,14 @@
86
86
+
#include <sys/types.h>
87
87
+
88
88
+
__BEGIN_DECLS
89
89
+
-size_t strlcpy(char *dst, const char *src, size_t siz);
90
90
+
-size_t strlcat(char *dst, const char *src, size_t siz);
91
91
+
char *strnstr(const char *str, const char *find, size_t str_len);
92
92
+
+#if defined(darwin) || defined(__APPLE__) || defined(MACOSX)
93
93
+
+size_t bsd_strlcpy(char *dst, const char *src, size_t siz);
94
94
+
+size_t bsd_strlcat(char *dst, const char *src, size_t siz);
95
95
+
+void bsd_strmode(mode_t mode, char *str);
96
96
+
+#else
97
97
+
void strmode(mode_t mode, char *str);
98
98
+
-
99
99
+
+#endif
100
100
+
void explicit_bzero(void *buf, size_t len);
101
101
+
__END_DECLS
102
102
+
103
103
+
diff --git a/src/Makefile.am b/src/Makefile.am
104
104
+
index ad83dbf..0f2a7ee 100644
105
105
+
--- a/src/Makefile.am
106
106
+
+++ b/src/Makefile.am
107
107
+
@@ -54,17 +54,21 @@ libbsd_la_DEPENDENCIES = \
108
108
+
libbsd.map
109
109
+
libbsd_la_LIBADD = \
110
110
+
$(CLOCK_GETTIME_LIBS)
111
111
+
+
112
112
+
+if IS_DARWIN
113
113
+
+libbsd_la_LDFLAGS = \
114
114
+
+ -Wl \
115
115
+
+ -version-number $(LIBBSD_ABI)
116
116
+
+else
117
117
+
libbsd_la_LDFLAGS = \
118
118
+
-Wl,--version-script=$(srcdir)/libbsd.map \
119
119
+
-version-number $(LIBBSD_ABI)
120
120
+
+endif
121
121
+
+
122
122
+
libbsd_la_SOURCES = \
123
123
+
arc4random.c \
124
124
+
- arc4random.h \
125
125
+
- arc4random_unix.h \
126
126
+
- arc4random_openbsd.h \
127
127
+
arc4random_uniform.c \
128
128
+
bsd_getopt.c \
129
129
+
- chacha_private.h \
130
130
+
closefrom.c \
131
131
+
dehumanize_number.c \
132
132
+
err.c \
133
133
+
@@ -117,6 +121,15 @@ libbsd_la_SOURCES += \
134
134
+
$(nil)
135
135
+
endif
136
136
+
137
137
+
+noinst_HEADERS = \
138
138
+
+ arc4random.h \
139
139
+
+ arc4random_bsd.h \
140
140
+
+ arc4random_linux.h \
141
141
+
+ arc4random_unix.h \
142
142
+
+ arc4random_osx.h \
143
143
+
+ arc4random_openbsd.h \
144
144
+
+ chacha_private.h
145
145
+
+
146
146
+
libbsd_ctor_a_SOURCES = \
147
147
+
setproctitle_ctor.c \
148
148
+
$(nil)
149
149
+
diff --git a/src/arc4random_bsd.h b/src/arc4random_bsd.h
150
150
+
new file mode 100644
151
151
+
index 0000000..ece2f85
152
152
+
--- /dev/null
153
153
+
+++ b/src/arc4random_bsd.h
154
154
+
@@ -0,0 +1,86 @@
155
155
+
+/* $OpenBSD: arc4random_freebsd.h,v 1.2 2015/01/15 06:57:18 deraadt Exp $ */
156
156
+
+
157
157
+
+/*
158
158
+
+ * Copyright (c) 1996, David Mazieres <dm@uun.org>
159
159
+
+ * Copyright (c) 2008, Damien Miller <djm@openbsd.org>
160
160
+
+ * Copyright (c) 2013, Markus Friedl <markus@openbsd.org>
161
161
+
+ * Copyright (c) 2014, Theo de Raadt <deraadt@openbsd.org>
162
162
+
+ *
163
163
+
+ * Permission to use, copy, modify, and distribute this software for any
164
164
+
+ * purpose with or without fee is hereby granted, provided that the above
165
165
+
+ * copyright notice and this permission notice appear in all copies.
166
166
+
+ *
167
167
+
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
168
168
+
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
169
169
+
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
170
170
+
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
171
171
+
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
172
172
+
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
173
173
+
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
174
174
+
+ */
175
175
+
+
176
176
+
+/*
177
177
+
+ * Stub functions for portability.
178
178
+
+ */
179
179
+
+
180
180
+
+#include <sys/mman.h>
181
181
+
+
182
182
+
+#include <pthread.h>
183
183
+
+#include <signal.h>
184
184
+
+
185
185
+
+static pthread_mutex_t arc4random_mtx = PTHREAD_MUTEX_INITIALIZER;
186
186
+
+#define _ARC4_LOCK() pthread_mutex_lock(&arc4random_mtx)
187
187
+
+#define _ARC4_UNLOCK() pthread_mutex_unlock(&arc4random_mtx)
188
188
+
+
189
189
+
+/*
190
190
+
+ * Unfortunately, pthread_atfork() is broken on FreeBSD (at least 9 and 10) if
191
191
+
+ * a program does not link to -lthr. Callbacks registered with pthread_atfork()
192
192
+
+ * appear to fail silently. So, it is not always possible to detect a PID
193
193
+
+ * wraparound.
194
194
+
+ */
195
195
+
+#define _ARC4_ATFORK(f) pthread_atfork(NULL, NULL, (f))
196
196
+
+
197
197
+
+static inline void
198
198
+
+_getentropy_fail(void)
199
199
+
+{
200
200
+
+ raise(SIGKILL);
201
201
+
+}
202
202
+
+
203
203
+
+static volatile sig_atomic_t _rs_forked;
204
204
+
+
205
205
+
+static inline void
206
206
+
+_rs_forkhandler(void)
207
207
+
+{
208
208
+
+ _rs_forked = 1;
209
209
+
+}
210
210
+
+
211
211
+
+static inline void
212
212
+
+_rs_forkdetect(void)
213
213
+
+{
214
214
+
+ static pid_t _rs_pid = 0;
215
215
+
+ pid_t pid = getpid();
216
216
+
+
217
217
+
+ if (_rs_pid == 0 || _rs_pid != pid || _rs_forked) {
218
218
+
+ _rs_pid = pid;
219
219
+
+ _rs_forked = 0;
220
220
+
+ if (rs)
221
221
+
+ memset(rs, 0, sizeof(*rs));
222
222
+
+ }
223
223
+
+}
224
224
+
+
225
225
+
+static inline int
226
226
+
+_rs_allocate(struct _rs **rsp, struct _rsx **rsxp)
227
227
+
+{
228
228
+
+ if ((*rsp = mmap(NULL, sizeof(**rsp), PROT_READ|PROT_WRITE,
229
229
+
+ MAP_ANON|MAP_PRIVATE, -1, 0)) == MAP_FAILED)
230
230
+
+ return (-1);
231
231
+
+
232
232
+
+ if ((*rsxp = mmap(NULL, sizeof(**rsxp), PROT_READ|PROT_WRITE,
233
233
+
+ MAP_ANON|MAP_PRIVATE, -1, 0)) == MAP_FAILED) {
234
234
+
+ munmap(*rsp, sizeof(**rsp));
235
235
+
+ return (-1);
236
236
+
+ }
237
237
+
+
238
238
+
+ _ARC4_ATFORK(_rs_forkhandler);
239
239
+
+ return (0);
240
240
+
+}
241
241
+
diff --git a/src/arc4random_linux.h b/src/arc4random_linux.h
242
242
+
new file mode 100644
243
243
+
index 0000000..d61a8db
244
244
+
--- /dev/null
245
245
+
+++ b/src/arc4random_linux.h
246
246
+
@@ -0,0 +1,86 @@
247
247
+
+/* $OpenBSD: arc4random_linux.h,v 1.8 2014/08/13 06:04:10 deraadt Exp $ */
248
248
+
+
249
249
+
+/*
250
250
+
+ * Copyright (c) 1996, David Mazieres <dm@uun.org>
251
251
+
+ * Copyright (c) 2008, Damien Miller <djm@openbsd.org>
252
252
+
+ * Copyright (c) 2013, Markus Friedl <markus@openbsd.org>
253
253
+
+ * Copyright (c) 2014, Theo de Raadt <deraadt@openbsd.org>
254
254
+
+ *
255
255
+
+ * Permission to use, copy, modify, and distribute this software for any
256
256
+
+ * purpose with or without fee is hereby granted, provided that the above
257
257
+
+ * copyright notice and this permission notice appear in all copies.
258
258
+
+ *
259
259
+
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
260
260
+
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
261
261
+
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
262
262
+
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
263
263
+
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
264
264
+
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
265
265
+
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
266
266
+
+ */
267
267
+
+
268
268
+
+/*
269
269
+
+ * Stub functions for portability.
270
270
+
+ */
271
271
+
+
272
272
+
+#include <sys/mman.h>
273
273
+
+
274
274
+
+#include <pthread.h>
275
275
+
+#include <signal.h>
276
276
+
+
277
277
+
+static pthread_mutex_t arc4random_mtx = PTHREAD_MUTEX_INITIALIZER;
278
278
+
+#define _ARC4_LOCK() pthread_mutex_lock(&arc4random_mtx)
279
279
+
+#define _ARC4_UNLOCK() pthread_mutex_unlock(&arc4random_mtx)
280
280
+
+
281
281
+
+#ifdef __GLIBC__
282
282
+
+extern void *__dso_handle;
283
283
+
+extern int __register_atfork(void (*)(void), void(*)(void), void (*)(void), void *);
284
284
+
+#define _ARC4_ATFORK(f) __register_atfork(NULL, NULL, (f), __dso_handle)
285
285
+
+#else
286
286
+
+#define _ARC4_ATFORK(f) pthread_atfork(NULL, NULL, (f))
287
287
+
+#endif
288
288
+
+
289
289
+
+static inline void
290
290
+
+_getentropy_fail(void)
291
291
+
+{
292
292
+
+ raise(SIGKILL);
293
293
+
+}
294
294
+
+
295
295
+
+static volatile sig_atomic_t _rs_forked;
296
296
+
+
297
297
+
+static inline void
298
298
+
+_rs_forkhandler(void)
299
299
+
+{
300
300
+
+ _rs_forked = 1;
301
301
+
+}
302
302
+
+
303
303
+
+static inline void
304
304
+
+_rs_forkdetect(void)
305
305
+
+{
306
306
+
+ static pid_t _rs_pid = 0;
307
307
+
+ pid_t pid = getpid();
308
308
+
+
309
309
+
+ if (_rs_pid == 0 || _rs_pid != pid || _rs_forked) {
310
310
+
+ _rs_pid = pid;
311
311
+
+ _rs_forked = 0;
312
312
+
+ if (rs)
313
313
+
+ memset(rs, 0, sizeof(*rs));
314
314
+
+ }
315
315
+
+}
316
316
+
+
317
317
+
+static inline int
318
318
+
+_rs_allocate(struct _rs **rsp, struct _rsx **rsxp)
319
319
+
+{
320
320
+
+ if ((*rsp = mmap(NULL, sizeof(**rsp), PROT_READ|PROT_WRITE,
321
321
+
+ MAP_ANON|MAP_PRIVATE, -1, 0)) == MAP_FAILED)
322
322
+
+ return (-1);
323
323
+
+
324
324
+
+ if ((*rsxp = mmap(NULL, sizeof(**rsxp), PROT_READ|PROT_WRITE,
325
325
+
+ MAP_ANON|MAP_PRIVATE, -1, 0)) == MAP_FAILED) {
326
326
+
+ munmap(*rsp, sizeof(**rsp));
327
327
+
+ return (-1);
328
328
+
+ }
329
329
+
+
330
330
+
+ _ARC4_ATFORK(_rs_forkhandler);
331
331
+
+ return (0);
332
332
+
+}
333
333
+
diff --git a/src/arc4random_osx.h b/src/arc4random_osx.h
334
334
+
new file mode 100644
335
335
+
index 0000000..14771a6
336
336
+
--- /dev/null
337
337
+
+++ b/src/arc4random_osx.h
338
338
+
@@ -0,0 +1,82 @@
339
339
+
+/* $OpenBSD: arc4random_osx.h,v 1.10 2015/09/11 11:52:55 deraadt Exp $ */
340
340
+
+
341
341
+
+/*
342
342
+
+ * Copyright (c) 1996, David Mazieres <dm@uun.org>
343
343
+
+ * Copyright (c) 2008, Damien Miller <djm@openbsd.org>
344
344
+
+ * Copyright (c) 2013, Markus Friedl <markus@openbsd.org>
345
345
+
+ * Copyright (c) 2014, Theo de Raadt <deraadt@openbsd.org>
346
346
+
+ *
347
347
+
+ * Permission to use, copy, modify, and distribute this software for any
348
348
+
+ * purpose with or without fee is hereby granted, provided that the above
349
349
+
+ * copyright notice and this permission notice appear in all copies.
350
350
+
+ *
351
351
+
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
352
352
+
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
353
353
+
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
354
354
+
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
355
355
+
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
356
356
+
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
357
357
+
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
358
358
+
+ */
359
359
+
+
360
360
+
+/*
361
361
+
+ * Stub functions for portability.
362
362
+
+ */
363
363
+
+
364
364
+
+#include <sys/mman.h>
365
365
+
+
366
366
+
+#include <unistd.h>
367
367
+
+#include <pthread.h>
368
368
+
+#include <signal.h>
369
369
+
+
370
370
+
+static pthread_mutex_t arc4random_mtx = PTHREAD_MUTEX_INITIALIZER;
371
371
+
+#define _ARC4_LOCK() pthread_mutex_lock(&arc4random_mtx)
372
372
+
+#define _ARC4_UNLOCK() pthread_mutex_unlock(&arc4random_mtx)
373
373
+
+
374
374
+
+#define _ARC4_ATFORK(f) pthread_atfork(NULL, NULL, (f))
375
375
+
+
376
376
+
+static inline void
377
377
+
+_getentropy_fail(void)
378
378
+
+{
379
379
+
+ raise(SIGKILL);
380
380
+
+}
381
381
+
+
382
382
+
+static volatile sig_atomic_t _rs_forked;
383
383
+
+
384
384
+
+static inline void
385
385
+
+_rs_forkhandler(void)
386
386
+
+{
387
387
+
+ _rs_forked = 1;
388
388
+
+}
389
389
+
+
390
390
+
+static inline void
391
391
+
+_rs_forkdetect(void)
392
392
+
+{
393
393
+
+ static pid_t _rs_pid = 0;
394
394
+
+ pid_t pid = getpid();
395
395
+
+
396
396
+
+ if (_rs_pid == 0 || _rs_pid != pid || _rs_forked) {
397
397
+
+ _rs_pid = pid;
398
398
+
+ _rs_forked = 0;
399
399
+
+ if (rs)
400
400
+
+ memset(rs, 0, sizeof(*rs));
401
401
+
+ }
402
402
+
+}
403
403
+
+
404
404
+
+static inline int
405
405
+
+_rs_allocate(struct _rs **rsp, struct _rsx **rsxp)
406
406
+
+{
407
407
+
+ if ((*rsp = mmap(NULL, sizeof(**rsp), PROT_READ|PROT_WRITE,
408
408
+
+ MAP_ANON|MAP_PRIVATE, -1, 0)) == MAP_FAILED)
409
409
+
+ return (-1);
410
410
+
+
411
411
+
+ if ((*rsxp = mmap(NULL, sizeof(**rsxp), PROT_READ|PROT_WRITE,
412
412
+
+ MAP_ANON|MAP_PRIVATE, -1, 0)) == MAP_FAILED) {
413
413
+
+ munmap(*rsp, sizeof(**rsp));
414
414
+
+ *rsp = NULL;
415
415
+
+ return (-1);
416
416
+
+ }
417
417
+
+
418
418
+
+ _ARC4_ATFORK(_rs_forkhandler);
419
419
+
+ return (0);
420
420
+
+}
421
421
+
diff --git a/src/fgetln.c b/src/fgetln.c
422
422
+
index 4d1726e..9c73788 100644
423
423
+
--- a/src/fgetln.c
424
424
+
+++ b/src/fgetln.c
425
425
+
@@ -30,7 +30,9 @@
426
426
+
#include <sys/types.h>
427
427
+
#include <string.h>
428
428
+
429
429
+
+#if !defined(darwin) && !defined(__APPLE__) && !defined(MACOSX)
430
430
+
#include "local-link.h"
431
431
+
+#endif
432
432
+
433
433
+
#ifdef HAVE_GETLINE
434
434
+
struct filebuf {
435
435
+
@@ -75,9 +77,11 @@ fgetln(FILE *stream, size_t *len)
436
436
+
return fb->buf;
437
437
+
}
438
438
+
}
439
439
+
+#if !defined(darwin) && !defined(__APPLE__) && !defined(MACOSX)
440
440
+
libbsd_link_warning(fgetln,
441
441
+
"This functions cannot be safely ported, use getline(3) "
442
442
+
"instead, as it is supported by GNU and POSIX.1-2008.")
443
443
+
+#endif
444
444
+
#else
445
445
+
#error "Function fgetln() needs to be ported."
446
446
+
#endif
447
447
+
diff --git a/src/fpurge.c b/src/fpurge.c
448
448
+
index 462535a..e7eb46f 100644
449
449
+
--- a/src/fpurge.c
450
450
+
+++ b/src/fpurge.c
451
451
+
@@ -26,9 +26,11 @@
452
452
+
453
453
+
#include <errno.h>
454
454
+
#include <stdio.h>
455
455
+
+#if HAVE___FPURGE
456
456
+
#include <stdio_ext.h>
457
457
+
+#endif
458
458
+
459
459
+
-#ifdef HAVE___FPURGE
460
460
+
+#ifdef HAVE___FPURGE /* glibc >= 2.2, Haiku, Solaris >= 7 */
461
461
+
int
462
462
+
fpurge(FILE *fp)
463
463
+
{
464
464
+
@@ -42,5 +44,55 @@ fpurge(FILE *fp)
465
465
+
return 0;
466
466
+
}
467
467
+
#else
468
468
+
-#error "Function fpurge() needs to be ported."
469
469
+
+#define fp_ fp
470
470
+
+//#error "Function fpurge() needs to be ported."
471
471
+
+//#elif HAVE_FPURGE /* FreeBSD, NetBSD, OpenBSD, DragonFly, Mac OS X, Cygwin 1.7 */
472
472
+
+int
473
473
+
+fpurge(FILE *fp)
474
474
+
+{
475
475
+
+ if (fp == NULL || fileno(fp) < 0) {
476
476
+
+ errno = EBADF;
477
477
+
+ return EOF;
478
478
+
+ }
479
479
+
+
480
480
+
+ /* Call the system's fpurge function. */
481
481
+
+# undef fpurge
482
482
+
+# if !HAVE_DECL_FPURGE
483
483
+
+ extern int fpurge (FILE *);
484
484
+
+# endif
485
485
+
+ int result = fpurge (fp);
486
486
+
+# if defined __sferror || defined __DragonFly__ /* FreeBSD, NetBSD, OpenBSD, DragonFly, Mac OS X, Cygwin */
487
487
+
+ if (result == 0)
488
488
+
+ /* Correct the invariants that fpurge broke.
489
489
+
+ <stdio.h> on BSD systems says:
490
490
+
+ "The following always hold: if _flags & __SRD, _w is 0."
491
491
+
+ If this invariant is not fulfilled and the stream is read-write but
492
492
+
+ currently reading, subsequent putc or fputc calls will write directly
493
493
+
+ into the buffer, although they shouldn't be allowed to. */
494
494
+
+ if ((fp_->_flags & __SRD) != 0)
495
495
+
+ fp_->_w = 0;
496
496
+
+#endif
497
497
+
+ return result;
498
498
+
+}
499
499
+
+//#endif
500
500
+
+#endif
501
501
+
+
502
502
+
+#ifdef TEST
503
503
+
+int
504
504
+
+main()
505
505
+
+{
506
506
+
+ static FILE fp_bad;
507
507
+
+ FILE *fp;
508
508
+
+
509
509
+
+ if (fpurge(&fp_bad) == 0)
510
510
+
+ return 1;
511
511
+
+
512
512
+
+ fp = fopen("/dev/zero", "r");
513
513
+
+ if (fpurge(fp) < 0)
514
514
+
+ return 1;
515
515
+
+
516
516
+
+ fclose(fp);
517
517
+
+
518
518
+
+ return 0;
519
519
+
+}
520
520
+
#endif
521
521
+
diff --git a/src/funopen.c b/src/funopen.c
522
522
+
index 7d6ae31..9963162 100644
523
523
+
--- a/src/funopen.c
524
524
+
+++ b/src/funopen.c
525
525
+
@@ -137,6 +137,7 @@ funopen(const void *cookie,
526
526
+
527
527
+
return fopencookie(cookiewrap, mode, funcswrap);
528
528
+
}
529
529
+
+#elif defined(darwin) || defined(__APPLE__) || defined(MACOSX)
530
530
+
#else
531
531
+
#error "Function funopen() needs to be ported."
532
532
+
#endif
533
533
+
diff --git a/src/getentropy.c b/src/getentropy.c
534
534
+
index 3f11a1e..8a23a07 100644
535
535
+
--- a/src/getentropy.c
536
536
+
+++ b/src/getentropy.c
537
537
+
@@ -28,9 +28,7 @@
538
538
+
#include "getentropy_linux.c"
539
539
+
#elif defined(__GNU__)
540
540
+
#include "getentropy_hurd.c"
541
541
+
-#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
542
542
+
-#include "getentropy_bsd.c"
543
543
+
-#elif defined(__NetBSD__)
544
544
+
+#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__NetBSD__)
545
545
+
#include "getentropy_bsd.c"
546
546
+
#elif defined(__sun)
547
547
+
#include "getentropy_solaris.c"
548
548
+
diff --git a/src/hash/sha512.h b/src/hash/sha512.h
549
549
+
index 4f368a1..ab22fc1 100644
550
550
+
--- a/src/hash/sha512.h
551
551
+
+++ b/src/hash/sha512.h
552
552
+
@@ -29,7 +29,11 @@
553
553
+
#ifndef _SHA512_H_
554
554
+
#define _SHA512_H_
555
555
+
556
556
+
+#if defined(darwin) || defined(__APPLE__) || defined(MACOSX)
557
557
+
+#include <stdint.h>
558
558
+
+#else
559
559
+
#include <sys/types.h>
560
560
+
+#endif
561
561
+
562
562
+
#define SHA512_DIGEST_LENGTH 64
563
563
+
564
564
+
diff --git a/src/hash/sha512c.c b/src/hash/sha512c.c
565
565
+
index c2a93be..f69013d 100644
566
566
+
--- a/src/hash/sha512c.c
567
567
+
+++ b/src/hash/sha512c.c
568
568
+
@@ -27,7 +27,11 @@
569
569
+
#include <sys/cdefs.h>
570
570
+
__FBSDID("$FreeBSD$");
571
571
+
572
572
+
+#if defined(darwin) || defined(__APPLE__) || defined(MACOSX)
573
573
+
+#include <machine/endian.h>
574
574
+
+#else
575
575
+
#include <sys/endian.h>
576
576
+
+#endif
577
577
+
#include <sys/types.h>
578
578
+
579
579
+
#include <string.h>
580
580
+
diff --git a/src/nlist.c b/src/nlist.c
581
581
+
index 0cffe55..f785b61 100644
582
582
+
--- a/src/nlist.c
583
583
+
+++ b/src/nlist.c
584
584
+
@@ -27,6 +27,7 @@
585
585
+
* SUCH DAMAGE.
586
586
+
*/
587
587
+
588
588
+
+#if !defined(darwin) && !defined(__APPLE__) && !defined(MACOSX)
589
589
+
#if defined(LIBC_SCCS) && !defined(lint)
590
590
+
static char sccsid[] = "@(#)nlist.c 8.1 (Berkeley) 6/4/93";
591
591
+
#endif /* LIBC_SCCS and not lint */
592
592
+
@@ -409,3 +410,4 @@ elf_sym_to_nlist(struct nlist *nl, Elf_Sym *s, Elf_Shdr *shdr, int shnum)
593
593
+
nl->n_type |= N_EXT;
594
594
+
}
595
595
+
#endif /* _NLIST_DO_ELF */
596
596
+
+#endif
597
597
+
diff --git a/src/setproctitle.c b/src/setproctitle.c
598
598
+
index c18c61c..b1b1591 100644
599
599
+
--- a/src/setproctitle.c
600
600
+
+++ b/src/setproctitle.c
601
601
+
@@ -32,6 +32,11 @@
602
602
+
#include <unistd.h>
603
603
+
#include <string.h>
604
604
+
605
605
+
+#if defined(darwin) || defined(__APPLE__) || defined(MACOSX)
606
606
+
+#define __asm__(x)
607
607
+
+extern char **environ;
608
608
+
+#endif
609
609
+
+
610
610
+
static struct {
611
611
+
/* Original value. */
612
612
+
const char *arg0;
613
613
+
@@ -287,7 +292,14 @@ __asm__(".symver setproctitle_impl,setproctitle@@LIBBSD_0.5");
614
614
+
* for code linking against that version, and change the default to use the
615
615
+
* new version, so that new code depends on the implemented version. */
616
616
+
#ifdef HAVE_TYPEOF
617
617
+
+#if defined(darwin) || defined(__APPLE__) || defined(MACOSX)
618
618
+
+//
619
619
+
+// HACK: even weak aliasing breaks in clang so just comment this out for now
620
620
+
+//
621
621
+
+// extern typeof(setproctitle_impl) setproctitle_stub __attribute__((weak, alias("setproctitle_impl")));
622
622
+
+#else
623
623
+
extern typeof(setproctitle_impl) setproctitle_stub __attribute__((alias("setproctitle_impl")));
624
624
+
+#endif
625
625
+
#else
626
626
+
void setproctitle_stub(const char *fmt, ...)
627
627
+
__attribute__((alias("setproctitle_impl")));
628
628
+
diff --git a/src/strlcat.c b/src/strlcat.c
629
629
+
index 21c8afb..e036132 100644
630
630
+
--- a/src/strlcat.c
631
631
+
+++ b/src/strlcat.c
632
632
+
@@ -27,7 +27,11 @@
633
633
+
* If retval >= siz, truncation occurred.
634
634
+
*/
635
635
+
size_t
636
636
+
+#if defined(darwin) || defined(__APPLE__) || defined(MACOSX)
637
637
+
+bsd_strlcat(char *dst, const char *src, size_t siz)
638
638
+
+#else
639
639
+
strlcat(char *dst, const char *src, size_t siz)
640
640
+
+#endif
641
641
+
{
642
642
+
char *d = dst;
643
643
+
const char *s = src;
644
644
+
diff --git a/src/strlcpy.c b/src/strlcpy.c
645
645
+
index 1719d35..c63591d 100644
646
646
+
--- a/src/strlcpy.c
647
647
+
+++ b/src/strlcpy.c
648
648
+
@@ -25,7 +25,11 @@
649
649
+
* Returns strlen(src); if retval >= siz, truncation occurred.
650
650
+
*/
651
651
+
size_t
652
652
+
+#if defined(darwin) || defined(__APPLE__) || defined(MACOSX)
653
653
+
+bsd_strlcpy(char *dst, const char *src, size_t siz)
654
654
+
+#else
655
655
+
strlcpy(char *dst, const char *src, size_t siz)
656
656
+
+#endif
657
657
+
{
658
658
+
char *d = dst;
659
659
+
const char *s = src;
660
660
+
diff --git a/src/strmode.c b/src/strmode.c
661
661
+
index 8d825ae..c1b5f8d 100644
662
662
+
--- a/src/strmode.c
663
663
+
+++ b/src/strmode.c
664
664
+
@@ -37,7 +37,11 @@ static char sccsid[] = "@(#)strmode.c 8.3 (Berkeley) 8/15/94";
665
665
+
#include <string.h>
666
666
+
667
667
+
void
668
668
+
+#if defined(darwin) || defined(__APPLE__) || defined(MACOSX)
669
669
+
+bsd_strmode(mode_t mode, char *p)
670
670
+
+#else
671
671
+
strmode(mode_t mode, char *p)
672
672
+
+#endif
673
673
+
{
674
674
+
/* print type */
675
675
+
switch (mode & S_IFMT) {
+9
-18
pkgs/development/libraries/libbsd/default.nix
···
1
1
-
{ stdenv, fetchFromGitHub, autoreconfHook }:
1
1
+
{ stdenv, fetchurl, autoreconfHook }:
2
2
3
3
stdenv.mkDerivation rec {
4
4
name = "libbsd-${version}";
5
5
version = "0.8.3";
6
6
7
7
-
nativeBuildInputs = [ autoreconfHook ];
7
7
+
src = fetchurl {
8
8
+
url = "http://libbsd.freedesktop.org/releases/${name}.tar.xz";
9
9
+
sha256 = "1a1l7afchlvvj2zfi7ajcg26bbkh5i98y2v5h9j5p1px9m7n6jwk";
10
10
+
};
8
11
9
9
-
preAutoreconf = "mkdir m4";
12
12
+
# darwin changes configure.ac which means we need to regenerate
13
13
+
# the configure scripts
14
14
+
nativeBuildInputs = [ autoreconfHook ];
10
15
11
11
-
patchPhase = ''
12
12
-
substituteInPlace configure.ac \
13
13
-
--replace "m4_esyscmd([./get-version])" "${version}"
14
14
-
sed -i '38i#undef strlcpy' include/bsd/string.h
15
15
-
sed -i '38i#undef strlcat' include/bsd/string.h
16
16
-
substituteInPlace src/setproctitle.c \
17
17
-
--replace 'extern typeof(setproctitle_impl) setproctitle_stub __attribute__((weak, alias("setproctitle_impl")));' ""
18
18
-
'';
19
19
-
20
20
-
src = fetchFromGitHub {
21
21
-
owner = "JackieXie168";
22
22
-
repo = "libbsd";
23
23
-
rev = "macosx-${version}";
24
24
-
sha256 = "1g5h6d7i297m0hs2l0dxvsx6p0z96959pzgp75drbb7mkrf32p2z";
25
25
-
};
16
16
+
patches = stdenv.lib.optionals stdenv.isDarwin [ ./darwin.patch ];
26
17
27
18
meta = with stdenv.lib; {
28
19
description = "Common functions found on BSD systems";