View | Details | Raw Unified | Return to bug 266227 | Differences between
and this patch

Collapse All | Expand All

(-)b/include/stdlib.h (-2 / +27 lines)
Lines 311-318 int mergesort_b(void *, size_t, size_t, int (^)(const void *, const void *)); Link Here
311
int	 mkostemp(char *, int);
311
int	 mkostemp(char *, int);
312
int	 mkostemps(char *, int, int);
312
int	 mkostemps(char *, int, int);
313
int	 mkostempsat(int, char *, int, int);
313
int	 mkostempsat(int, char *, int, int);
314
void	 qsort_r(void *, size_t, size_t, void *,
314
void	 qsort_r(void *, size_t, size_t,
315
	    int (*)(void *, const void *, const void *));
315
	    int (*)(const void *, const void *, void *), void *);
316
int	 radixsort(const unsigned char **, int, const unsigned char *,
316
int	 radixsort(const unsigned char **, int, const unsigned char *,
317
	    unsigned);
317
	    unsigned);
318
void	*reallocarray(void *, size_t, size_t) __result_use_check
318
void	*reallocarray(void *, size_t, size_t) __result_use_check
Lines 332-337 __int64_t Link Here
332
__uint64_t
332
__uint64_t
333
	 strtouq(const char *, char **, int);
333
	 strtouq(const char *, char **, int);
334
334
335
/*
336
 * Attempt to trap calls of the historical qsort_r() function. The order
337
 * of the last two arguments of this function have changed. If the last
338
 * argument matches the type of the traditional comparator function,
339
 * apply a workaround where we explicitly link against qsort_r@FBSD_1.0
340
 * in case these functions are called with the historical interface.
341
 */
342
#if defined(__generic) || defined(__cplusplus)
343
void __qsort_r_compat(void *, size_t, size_t, void *,
344
	    int (*)(void *, const void *, const void *));
345
__sym_compat(qsort_r, __qsort_r_compat, FBSD_1.0);
346
#endif
347
#if defined(__generic) && !defined(__cplusplus)
348
#define	qsort_r(base, nel, width, arg4, arg5)				\
349
    __generic(arg5, int (*)(void *, const void *, const void *),	\
350
        __qsort_r_compat, qsort_r)(base, nel, width, arg4, arg5)
351
#elif defined(__cplusplus)
352
__END_DECLS
353
static inline void qsort_r(void *base, size_t nmemb, size_t size, void *thunk,
354
    int (*compar)(void *, const void *, const void *)) {
355
	__qsort_r_compat(base, nmemb, size, thunk, compar);
356
}
357
__BEGIN_DECLS
358
#endif
359
335
extern char *suboptarg;			/* getsubopt(3) external variable */
360
extern char *suboptarg;			/* getsubopt(3) external variable */
336
#endif /* __BSD_VISIBLE */
361
#endif /* __BSD_VISIBLE */
337
362
(-)b/lib/libc/gen/scandir-compat11.c (-4 / +4 lines)
Lines 58-65 __FBSDID("$FreeBSD$"); Link Here
58
58
59
#define	SELECT(x)	select(x)
59
#define	SELECT(x)	select(x)
60
60
61
static int freebsd11_alphasort_thunk(void *thunk, const void *p1,
61
static int freebsd11_alphasort_thunk(const void *p1, const void *p2,
62
    const void *p2);
62
    void *thunk);
63
63
64
int
64
int
65
freebsd11_scandir(const char *dirname, struct freebsd11_dirent ***namelist,
65
freebsd11_scandir(const char *dirname, struct freebsd11_dirent ***namelist,
Lines 116-122 freebsd11_scandir(const char *dirname, struct freebsd11_dirent ***namelist, Link Here
116
	closedir(dirp);
116
	closedir(dirp);
117
	if (numitems && dcomp != NULL)
117
	if (numitems && dcomp != NULL)
118
		qsort_r(names, numitems, sizeof(struct freebsd11_dirent *),
118
		qsort_r(names, numitems, sizeof(struct freebsd11_dirent *),
119
		    &dcomp, freebsd11_alphasort_thunk);
119
		    freebsd11_alphasort_thunk, &dcomp);
120
	*namelist = names;
120
	*namelist = names;
121
	return (numitems);
121
	return (numitems);
122
122
Lines 141-147 freebsd11_alphasort(const struct freebsd11_dirent **d1, Link Here
141
}
141
}
142
142
143
static int
143
static int
144
freebsd11_alphasort_thunk(void *thunk, const void *p1, const void *p2)
144
freebsd11_alphasort_thunk(const void *p1, const void *p2, void *thunk)
145
{
145
{
146
	int (*dc)(const struct freebsd11_dirent **, const struct
146
	int (*dc)(const struct freebsd11_dirent **, const struct
147
	    freebsd11_dirent **);
147
	    freebsd11_dirent **);
(-)b/lib/libc/gen/scandir.c (-3 / +3 lines)
Lines 63-69 typedef DECLARE_BLOCK(int, select_block, const struct dirent *); Link Here
63
typedef DECLARE_BLOCK(int, dcomp_block, const struct dirent **,
63
typedef DECLARE_BLOCK(int, dcomp_block, const struct dirent **,
64
    const struct dirent **);
64
    const struct dirent **);
65
#else
65
#else
66
static int alphasort_thunk(void *thunk, const void *p1, const void *p2);
66
static int alphasort_thunk(const void *p1, const void *p2, void *thunk);
67
#endif
67
#endif
68
68
69
static int
69
static int
Lines 123-129 scandir_dirp(DIR *dirp, struct dirent ***namelist, Link Here
123
		qsort_b(names, numitems, sizeof(struct dirent *), (void*)dcomp);
123
		qsort_b(names, numitems, sizeof(struct dirent *), (void*)dcomp);
124
#else
124
#else
125
		qsort_r(names, numitems, sizeof(struct dirent *),
125
		qsort_r(names, numitems, sizeof(struct dirent *),
126
		    &dcomp, alphasort_thunk);
126
		    alphasort_thunk, &dcomp);
127
#endif
127
#endif
128
	*namelist = names;
128
	*namelist = names;
129
	return (numitems);
129
	return (numitems);
Lines 199-205 versionsort(const struct dirent **d1, const struct dirent **d2) Link Here
199
}
199
}
200
200
201
static int
201
static int
202
alphasort_thunk(void *thunk, const void *p1, const void *p2)
202
alphasort_thunk(const void *p1, const void *p2, void *thunk)
203
{
203
{
204
	int (*dc)(const struct dirent **, const struct dirent **);
204
	int (*dc)(const struct dirent **, const struct dirent **);
205
205
(-)b/lib/libc/stdlib/Makefile.inc (-2 / +2 lines)
Lines 11-18 MISRCS+=C99_Exit.c a64l.c abort.c abs.c atexit.c atof.c atoi.c atol.c atoll.c \ Link Here
11
	getsubopt.c hcreate.c hcreate_r.c hdestroy_r.c heapsort.c heapsort_b.c \
11
	getsubopt.c hcreate.c hcreate_r.c hdestroy_r.c heapsort.c heapsort_b.c \
12
	hsearch_r.c imaxabs.c imaxdiv.c \
12
	hsearch_r.c imaxabs.c imaxdiv.c \
13
	insque.c l64a.c labs.c ldiv.c llabs.c lldiv.c lsearch.c \
13
	insque.c l64a.c labs.c ldiv.c llabs.c lldiv.c lsearch.c \
14
	merge.c mergesort_b.c ptsname.c qsort.c qsort_r.c qsort_s.c \
14
	merge.c mergesort_b.c ptsname.c qsort.c qsort_r.c qsort_r_compat.c \
15
	quick_exit.c radixsort.c rand.c \
15
	qsort_s.c quick_exit.c radixsort.c rand.c \
16
	random.c reallocarray.c reallocf.c realpath.c remque.c \
16
	random.c reallocarray.c reallocf.c realpath.c remque.c \
17
	set_constraint_handler_s.c strfmon.c strtoimax.c \
17
	set_constraint_handler_s.c strfmon.c strtoimax.c \
18
	strtol.c strtold.c strtoll.c strtoq.c strtoul.c strtonum.c strtoull.c \
18
	strtol.c strtold.c strtoll.c strtoq.c strtoul.c strtonum.c strtoull.c \
(-)b/lib/libc/stdlib/Symbol.map (-1 / +1 lines)
Lines 49-55 FBSD_1.0 { Link Here
49
	lfind;
49
	lfind;
50
	mergesort;
50
	mergesort;
51
	putenv;
51
	putenv;
52
	qsort_r;
53
	qsort;
52
	qsort;
54
	radixsort;
53
	radixsort;
55
	sradixsort;
54
	sradixsort;
Lines 130-135 FBSD_1.6 { Link Here
130
129
131
FBSD_1.7 {
130
FBSD_1.7 {
132
	clearenv;
131
	clearenv;
132
	qsort_r;
133
};
133
};
134
134
135
FBSDprivate_1.0 {
135
FBSDprivate_1.0 {
(-)b/lib/libc/stdlib/qsort.3 (-3 / +9 lines)
Lines 32-38 Link Here
32
.\"     @(#)qsort.3	8.1 (Berkeley) 6/4/93
32
.\"     @(#)qsort.3	8.1 (Berkeley) 6/4/93
33
.\" $FreeBSD$
33
.\" $FreeBSD$
34
.\"
34
.\"
35
.Dd January 20, 2020
35
.Dd September 12, 2022
36
.Dt QSORT 3
36
.Dt QSORT 3
37
.Os
37
.Os
38
.Sh NAME
38
.Sh NAME
Lines 67-74 Link Here
67
.Fa "void *base"
67
.Fa "void *base"
68
.Fa "size_t nmemb"
68
.Fa "size_t nmemb"
69
.Fa "size_t size"
69
.Fa "size_t size"
70
.Fa "int \*[lp]*compar\*[rp]\*[lp]const void *, const void *, void *\*[rp]"
70
.Fa "void *thunk"
71
.Fa "void *thunk"
71
.Fa "int \*[lp]*compar\*[rp]\*[lp]void *, const void *, const void *\*[rp]"
72
.Fc
72
.Fc
73
.Ft int
73
.Ft int
74
.Fo heapsort
74
.Fo heapsort
Lines 157-163 function behaves identically to Link Here
157
.Fn qsort ,
157
.Fn qsort ,
158
except that it takes an additional argument,
158
except that it takes an additional argument,
159
.Fa thunk ,
159
.Fa thunk ,
160
which is passed unchanged as the first argument to function pointed to
160
which is passed unchanged as the last argument to function pointed to
161
.Fa compar .
161
.Fa compar .
162
This allows the comparison function to access additional
162
This allows the comparison function to access additional
163
data without using global variables, and thus
163
data without using global variables, and thus
Lines 436-438 K.3.6.3.2. Link Here
436
The variants of these functions that take blocks as arguments first appeared in
436
The variants of these functions that take blocks as arguments first appeared in
437
Mac OS X.
437
Mac OS X.
438
This implementation was created by David Chisnall.
438
This implementation was created by David Chisnall.
439
.Pp
440
In
441
.Fx 14.0 ,
442
the prototype of
443
.Fn qsort_r
444
was updated to match glibc.
(-)b/lib/libc/stdlib/qsort.c (-2 / +14 lines)
Lines 42-47 __FBSDID("$FreeBSD$"); Link Here
42
#include "libc_private.h"
42
#include "libc_private.h"
43
43
44
#if defined(I_AM_QSORT_R)
44
#if defined(I_AM_QSORT_R)
45
typedef int		 cmp_t(const void *, const void *, void *);
46
#elif defined(I_AM_QSORT_R_COMPAT)
45
typedef int		 cmp_t(void *, const void *, const void *);
47
typedef int		 cmp_t(void *, const void *, const void *);
46
#elif defined(I_AM_QSORT_S)
48
#elif defined(I_AM_QSORT_S)
47
typedef int		 cmp_t(const void *, const void *, void *);
49
typedef int		 cmp_t(const void *, const void *, void *);
Lines 72-77 swapfunc(char *a, char *b, size_t es) Link Here
72
	if ((n) > 0) swapfunc(a, b, n)
74
	if ((n) > 0) swapfunc(a, b, n)
73
75
74
#if defined(I_AM_QSORT_R)
76
#if defined(I_AM_QSORT_R)
77
#define	CMP(t, x, y) (cmp((x), (y), (t)))
78
#elif defined(I_AM_QSORT_R_COMPAT)
75
#define	CMP(t, x, y) (cmp((t), (x), (y)))
79
#define	CMP(t, x, y) (cmp((t), (x), (y)))
76
#elif defined(I_AM_QSORT_S)
80
#elif defined(I_AM_QSORT_S)
77
#define	CMP(t, x, y) (cmp((x), (y), (t)))
81
#define	CMP(t, x, y) (cmp((x), (y), (t)))
Lines 81-87 swapfunc(char *a, char *b, size_t es) Link Here
81
85
82
static inline char *
86
static inline char *
83
med3(char *a, char *b, char *c, cmp_t *cmp, void *thunk
87
med3(char *a, char *b, char *c, cmp_t *cmp, void *thunk
84
#if !defined(I_AM_QSORT_R) && !defined(I_AM_QSORT_S)
88
#if !defined(I_AM_QSORT_R) && !defined(I_AM_QSORT_R_COMPAT) && !defined(I_AM_QSORT_S)
85
__unused
89
__unused
86
#endif
90
#endif
87
)
91
)
Lines 97-102 __unused Link Here
97
 */
101
 */
98
#if defined(I_AM_QSORT_R)
102
#if defined(I_AM_QSORT_R)
99
#define local_qsort local_qsort_r
103
#define local_qsort local_qsort_r
104
#elif defined(I_AM_QSORT_R_COMPAT)
105
#define local_qsort local_qsort_r_compat
100
#elif defined(I_AM_QSORT_S)
106
#elif defined(I_AM_QSORT_S)
101
#define local_qsort local_qsort_s
107
#define local_qsort local_qsort_s
102
#endif
108
#endif
Lines 211-220 local_qsort(void *a, size_t n, size_t es, cmp_t *cmp, void *thunk) Link Here
211
217
212
#if defined(I_AM_QSORT_R)
218
#if defined(I_AM_QSORT_R)
213
void
219
void
214
qsort_r(void *a, size_t n, size_t es, void *thunk, cmp_t *cmp)
220
(qsort_r)(void *a, size_t n, size_t es, cmp_t *cmp, void *thunk)
215
{
221
{
216
	local_qsort_r(a, n, es, cmp, thunk);
222
	local_qsort_r(a, n, es, cmp, thunk);
217
}
223
}
224
#elif defined(I_AM_QSORT_R_COMPAT)
225
void
226
__qsort_r_compat(void *a, size_t n, size_t es, void *thunk, cmp_t *cmp)
227
{
228
	local_qsort_r_compat(a, n, es, cmp, thunk);
229
}
218
#elif defined(I_AM_QSORT_S)
230
#elif defined(I_AM_QSORT_S)
219
errno_t
231
errno_t
220
qsort_s(void *a, rsize_t n, rsize_t es, cmp_t *cmp, void *thunk)
232
qsort_s(void *a, rsize_t n, rsize_t es, cmp_t *cmp, void *thunk)
(-)b/lib/libc/stdlib/qsort_r.c (-11 lines)
Lines 4-19 Link Here
4
 *
4
 *
5
 * $FreeBSD$
5
 * $FreeBSD$
6
 */
6
 */
7
#include "block_abi.h"
8
#define I_AM_QSORT_R
7
#define I_AM_QSORT_R
9
#include "qsort.c"
8
#include "qsort.c"
10
11
typedef DECLARE_BLOCK(int, qsort_block, const void *, const void *);
12
13
void
14
qsort_b(void *base, size_t nel, size_t width, qsort_block compar)
15
{
16
	qsort_r(base, nel, width, compar,
17
		(int (*)(void *, const void *, const void *))
18
		GET_BLOCK_FUNCTION(compar));
19
}
(-)b/lib/libc/stdlib/qsort_r_compat.c (+21 lines)
Added Link Here
1
/*
2
 * This file is in the public domain.  Originally written by Garrett
3
 * A. Wollman.
4
 *
5
 * $FreeBSD$
6
 */
7
#include "block_abi.h"
8
#define I_AM_QSORT_R_COMPAT
9
#include "qsort.c"
10
11
typedef DECLARE_BLOCK(int, qsort_block, const void *, const void *);
12
13
void
14
qsort_b(void *base, size_t nel, size_t width, qsort_block compar)
15
{
16
	__qsort_r_compat(base, nel, width, compar,
17
		(int (*)(void *, const void *, const void *))
18
		GET_BLOCK_FUNCTION(compar));
19
}
20
21
__sym_compat(qsort_r, __qsort_r_compat, FBSD_1.0);
(-)b/lib/libc/tests/stdlib/Makefile (+1 lines)
Lines 8-13 ATF_TESTS_C+= heapsort_test Link Here
8
ATF_TESTS_C+=		mergesort_test
8
ATF_TESTS_C+=		mergesort_test
9
ATF_TESTS_C+=		qsort_test
9
ATF_TESTS_C+=		qsort_test
10
ATF_TESTS_C+=		qsort_b_test
10
ATF_TESTS_C+=		qsort_b_test
11
ATF_TESTS_C+=		qsort_r_compat_test
11
ATF_TESTS_C+=		qsort_r_test
12
ATF_TESTS_C+=		qsort_r_test
12
ATF_TESTS_C+=		qsort_s_test
13
ATF_TESTS_C+=		qsort_s_test
13
ATF_TESTS_C+=		set_constraint_handler_s_test
14
ATF_TESTS_C+=		set_constraint_handler_s_test
(-)b/lib/libc/tests/stdlib/qsort_r_compat_test.c (+92 lines)
Added Link Here
1
/*-
2
 * Copyright (C) 2020 Edward Tomasz Napierala <trasz@FreeBSD.org>
3
 * Copyright (C) 2004 Maxim Sobolev <sobomax@FreeBSD.org>
4
 * All rights reserved.
5
 *
6
 * Redistribution and use in source and binary forms, with or without
7
 * modification, are permitted provided that the following conditions
8
 * are met:
9
 * 1. Redistributions of source code must retain the above copyright
10
 *    notice, this list of conditions and the following disclaimer.
11
 * 2. Redistributions in binary form must reproduce the above copyright
12
 *    notice, this list of conditions and the following disclaimer in the
13
 *    documentation and/or other materials provided with the distribution.
14
 *
15
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25
 * SUCH DAMAGE.
26
 */
27
28
/*
29
 * Test for historical qsort_r(3) routine.
30
 */
31
32
#include <sys/cdefs.h>
33
__FBSDID("$FreeBSD$");
34
35
#include <stdio.h>
36
#include <stdlib.h>
37
38
#include "test-sort.h"
39
40
#define	THUNK 42
41
42
static int
43
sorthelp_r(void *thunk, const void *a, const void *b)
44
{
45
	const int *oa, *ob;
46
47
	ATF_REQUIRE_EQ(*(int *)thunk, THUNK);
48
49
	oa = a;
50
	ob = b;
51
	/* Don't use "return *oa - *ob" since it's easy to cause overflow! */
52
	if (*oa > *ob)
53
		return (1);
54
	if (*oa < *ob)
55
		return (-1);
56
	return (0);
57
}
58
59
ATF_TC_WITHOUT_HEAD(qsort_r_compat_test);
60
ATF_TC_BODY(qsort_r_compat_test, tc)
61
{
62
	int testvector[IVEC_LEN];
63
	int sresvector[IVEC_LEN];
64
	int i, j;
65
	int thunk = THUNK;
66
67
	for (j = 2; j < IVEC_LEN; j++) {
68
		/* Populate test vectors */
69
		for (i = 0; i < j; i++)
70
			testvector[i] = sresvector[i] = initvector[i];
71
72
		/* Sort using qsort_r(3) */
73
		qsort_r(testvector, j, sizeof(testvector[0]), &thunk,
74
		    sorthelp_r);
75
		/* Sort using reference slow sorting routine */
76
		ssort(sresvector, j);
77
78
		/* Compare results */
79
		for (i = 0; i < j; i++)
80
			ATF_CHECK_MSG(testvector[i] == sresvector[i],
81
			    "item at index %d didn't match: %d != %d",
82
			    i, testvector[i], sresvector[i]);
83
	}
84
}
85
86
ATF_TP_ADD_TCS(tp)
87
{
88
89
	ATF_TP_ADD_TC(tp, qsort_r_compat_test);
90
91
	return (atf_no_error());
92
}
(-)b/lib/libc/tests/stdlib/qsort_r_test.c (-3 / +3 lines)
Lines 40-46 __FBSDID("$FreeBSD$"); Link Here
40
#define	THUNK 42
40
#define	THUNK 42
41
41
42
static int
42
static int
43
sorthelp_r(void *thunk, const void *a, const void *b)
43
sorthelp_r(const void *a, const void *b, void *thunk)
44
{
44
{
45
	const int *oa, *ob;
45
	const int *oa, *ob;
46
46
Lines 70-77 ATF_TC_BODY(qsort_r_test, tc) Link Here
70
			testvector[i] = sresvector[i] = initvector[i];
70
			testvector[i] = sresvector[i] = initvector[i];
71
71
72
		/* Sort using qsort_r(3) */
72
		/* Sort using qsort_r(3) */
73
		qsort_r(testvector, j, sizeof(testvector[0]), &thunk,
73
		qsort_r(testvector, j, sizeof(testvector[0]), sorthelp_r,
74
		    sorthelp_r);
74
		    &thunk);
75
		/* Sort using reference slow sorting routine */
75
		/* Sort using reference slow sorting routine */
76
		ssort(sresvector, j);
76
		ssort(sresvector, j);
77
77
(-)b/lib/libproc/proc_sym.c (-2 / +2 lines)
Lines 105-111 struct symsort_thunk { Link Here
105
};
105
};
106
106
107
static int
107
static int
108
symvalcmp(void *_thunk, const void *a1, const void *a2)
108
symvalcmp(const void *a1, const void *a2, void *_thunk)
109
{
109
{
110
	GElf_Sym sym1, sym2;
110
	GElf_Sym sym1, sym2;
111
	struct symsort_thunk *thunk;
111
	struct symsort_thunk *thunk;
Lines 192-198 load_symtab(Elf *e, struct symtab *symtab, u_long sh_type) Link Here
192
192
193
	thunk.e = e;
193
	thunk.e = e;
194
	thunk.symtab = symtab;
194
	thunk.symtab = symtab;
195
	qsort_r(symtab->index, nsyms, sizeof(u_int), &thunk, symvalcmp);
195
	qsort_r(symtab->index, nsyms, sizeof(u_int), symvalcmp, &thunk);
196
196
197
	return (0);
197
	return (0);
198
}
198
}
(-)b/sys/compat/linuxkpi/common/src/linux_compat.c (-2 / +2 lines)
Lines 2562-2568 struct list_sort_thunk { Link Here
2562
};
2562
};
2563
2563
2564
static inline int
2564
static inline int
2565
linux_le_cmp(void *priv, const void *d1, const void *d2)
2565
linux_le_cmp(const void *d1, const void *d2, void *priv)
2566
{
2566
{
2567
	struct list_head *le1, *le2;
2567
	struct list_head *le1, *le2;
2568
	struct list_sort_thunk *thunk;
2568
	struct list_sort_thunk *thunk;
Lines 2590-2596 list_sort(void *priv, struct list_head *head, int (*cmp)(void *priv, Link Here
2590
		ar[i++] = le;
2590
		ar[i++] = le;
2591
	thunk.cmp = cmp;
2591
	thunk.cmp = cmp;
2592
	thunk.priv = priv;
2592
	thunk.priv = priv;
2593
	qsort_r(ar, count, sizeof(struct list_head *), &thunk, linux_le_cmp);
2593
	qsort_r(ar, count, sizeof(struct list_head *), linux_le_cmp, &thunk);
2594
	INIT_LIST_HEAD(head);
2594
	INIT_LIST_HEAD(head);
2595
	for (i = 0; i < count; i++)
2595
	for (i = 0; i < count; i++)
2596
		list_add_tail(ar[i], head);
2596
		list_add_tail(ar[i], head);
(-)b/sys/dev/bhnd/nvram/bhnd_nvram_store_subr.c (-5 / +4 lines)
Lines 59-66 __FBSDID("$FreeBSD$"); Link Here
59
59
60
#include "bhnd_nvram_storevar.h"
60
#include "bhnd_nvram_storevar.h"
61
61
62
static int			 bhnd_nvstore_idx_cmp(void *ctx,
62
static int bhnd_nvstore_idx_cmp(const void *lhs, const void *rhs, void *ctx);
63
				     const void *lhs, const void *rhs);
64
63
65
/**
64
/**
66
 * Allocate and initialize a new path instance.
65
 * Allocate and initialize a new path instance.
Lines 198-204 bhnd_nvstore_index_append(struct bhnd_nvram_store *sc, Link Here
198
197
199
/* sort function for bhnd_nvstore_index_prepare() */
198
/* sort function for bhnd_nvstore_index_prepare() */
200
static int
199
static int
201
bhnd_nvstore_idx_cmp(void *ctx, const void *lhs, const void *rhs)
200
bhnd_nvstore_idx_cmp(const void *lhs, const void *rhs, void *ctx)
202
{
201
{
203
	struct bhnd_nvram_store	*sc;
202
	struct bhnd_nvram_store	*sc;
204
	void			*l_cookiep, *r_cookiep;
203
	void			*l_cookiep, *r_cookiep;
Lines 259-266 bhnd_nvstore_index_prepare(struct bhnd_nvram_store *sc, Link Here
259
	BHND_NVSTORE_LOCK_ASSERT(sc, MA_OWNED);
258
	BHND_NVSTORE_LOCK_ASSERT(sc, MA_OWNED);
260
259
261
	/* Sort the index table */
260
	/* Sort the index table */
262
	qsort_r(index->cookiep, index->count, sizeof(index->cookiep[0]), sc,
261
	qsort_r(index->cookiep, index->count, sizeof(index->cookiep[0]),
263
	    bhnd_nvstore_idx_cmp);
262
	    bhnd_nvstore_idx_cmp, sc);
264
263
265
	return (0);
264
	return (0);
266
}
265
}
(-)b/sys/dev/drm2/drm_linux_list_sort.c (-2 / +2 lines)
Lines 37-43 struct drm_list_sort_thunk { Link Here
37
};
37
};
38
38
39
static int
39
static int
40
drm_le_cmp(void *priv, const void *d1, const void *d2)
40
drm_le_cmp(const void *d1, const void *d2, void *priv)
41
{
41
{
42
	struct list_head *le1, *le2;
42
	struct list_head *le1, *le2;
43
	struct drm_list_sort_thunk *thunk;
43
	struct drm_list_sort_thunk *thunk;
Lines 68-74 drm_list_sort(void *priv, struct list_head *head, int (*cmp)(void *priv, Link Here
68
		ar[i++] = le;
68
		ar[i++] = le;
69
	thunk.cmp = cmp;
69
	thunk.cmp = cmp;
70
	thunk.priv = priv;
70
	thunk.priv = priv;
71
	qsort_r(ar, count, sizeof(struct list_head *), &thunk, drm_le_cmp);
71
	qsort_r(ar, count, sizeof(struct list_head *), drm_le_cmp, &thunk);
72
	INIT_LIST_HEAD(head);
72
	INIT_LIST_HEAD(head);
73
	for (i = 0; i < count; i++)
73
	for (i = 0; i < count; i++)
74
		list_add_tail(ar[i], head);
74
		list_add_tail(ar[i], head);
(-)b/sys/libkern/qsort.c (-5 / +5 lines)
Lines 36-42 __FBSDID("$FreeBSD$"); Link Here
36
#include <sys/libkern.h>
36
#include <sys/libkern.h>
37
37
38
#ifdef I_AM_QSORT_R
38
#ifdef I_AM_QSORT_R
39
typedef int		 cmp_t(void *, const void *, const void *);
39
typedef int		 cmp_t(const void *, const void *, void *);
40
#else
40
#else
41
typedef int		 cmp_t(const void *, const void *);
41
typedef int		 cmp_t(const void *, const void *);
42
#endif
42
#endif
Lines 88-94 swapfunc(char *a, char *b, size_t n, int swaptype_long, int swaptype_int) Link Here
88
	if ((n) > 0) swapfunc(a, b, n, swaptype_long, swaptype_int)
88
	if ((n) > 0) swapfunc(a, b, n, swaptype_long, swaptype_int)
89
89
90
#ifdef I_AM_QSORT_R
90
#ifdef I_AM_QSORT_R
91
#define	CMP(t, x, y) (cmp((t), (x), (y)))
91
#define	CMP(t, x, y) (cmp((x), (y), (t)))
92
#else
92
#else
93
#define	CMP(t, x, y) (cmp((x), (y)))
93
#define	CMP(t, x, y) (cmp((x), (y)))
94
#endif
94
#endif
Lines 107-113 __unused Link Here
107
107
108
#ifdef I_AM_QSORT_R
108
#ifdef I_AM_QSORT_R
109
void
109
void
110
qsort_r(void *a, size_t n, size_t es, void *thunk, cmp_t *cmp)
110
(qsort_r)(void *a, size_t n, size_t es, cmp_t *cmp, void *thunk)
111
#else
111
#else
112
#define	thunk NULL
112
#define	thunk NULL
113
void
113
void
Lines 192-198 loop: SWAPINIT(long, a, es); Link Here
192
		/* Recurse on left partition, then iterate on right partition */
192
		/* Recurse on left partition, then iterate on right partition */
193
		if (d1 > es) {
193
		if (d1 > es) {
194
#ifdef I_AM_QSORT_R
194
#ifdef I_AM_QSORT_R
195
			qsort_r(a, d1 / es, es, thunk, cmp);
195
			qsort_r(a, d1 / es, es, cmp, thunk);
196
#else
196
#else
197
			qsort(a, d1 / es, es, cmp);
197
			qsort(a, d1 / es, es, cmp);
198
#endif
198
#endif
Lines 208-214 loop: SWAPINIT(long, a, es); Link Here
208
		/* Recurse on right partition, then iterate on left partition */
208
		/* Recurse on right partition, then iterate on left partition */
209
		if (d2 > es) {
209
		if (d2 > es) {
210
#ifdef I_AM_QSORT_R
210
#ifdef I_AM_QSORT_R
211
			qsort_r(pn - d2, d2 / es, es, thunk, cmp);
211
			qsort_r(pn - d2, d2 / es, es, cmp, thunk);
212
#else
212
#else
213
			qsort(pn - d2, d2 / es, es, cmp);
213
			qsort(pn - d2, d2 / es, es, cmp);
214
#endif
214
#endif
(-)b/sys/netgraph/ng_ppp.c (-4 / +4 lines)
Lines 322-328 static void ng_ppp_frag_timeout(node_p node, hook_p hook, void *arg1, Link Here
322
static void	ng_ppp_frag_checkstale(node_p node);
322
static void	ng_ppp_frag_checkstale(node_p node);
323
static void	ng_ppp_frag_reset(node_p node);
323
static void	ng_ppp_frag_reset(node_p node);
324
static void	ng_ppp_mp_strategy(node_p node, int len, int *distrib);
324
static void	ng_ppp_mp_strategy(node_p node, int len, int *distrib);
325
static int	ng_ppp_intcmp(void *latency, const void *v1, const void *v2);
325
static int	ng_ppp_intcmp(const void *v1, const void *v2, void *latency);
326
static struct mbuf *ng_ppp_addproto(struct mbuf *m, uint16_t proto, int compOK);
326
static struct mbuf *ng_ppp_addproto(struct mbuf *m, uint16_t proto, int compOK);
327
static struct mbuf *ng_ppp_cutproto(struct mbuf *m, uint16_t *proto);
327
static struct mbuf *ng_ppp_cutproto(struct mbuf *m, uint16_t *proto);
328
static struct mbuf *ng_ppp_prepend(struct mbuf *m, const void *buf, int len);
328
static struct mbuf *ng_ppp_prepend(struct mbuf *m, const void *buf, int len);
Lines 2316-2323 ng_ppp_mp_strategy(node_p node, int len, int *distrib) Link Here
2316
	}
2316
	}
2317
2317
2318
	/* Sort active links by latency */
2318
	/* Sort active links by latency */
2319
	qsort_r(sortByLatency,
2319
	qsort_r(sortByLatency, priv->numActiveLinks, sizeof(*sortByLatency),
2320
	    priv->numActiveLinks, sizeof(*sortByLatency), latency, ng_ppp_intcmp);
2320
	    ng_ppp_intcmp, latency);
2321
2321
2322
	/* Find the interval we need (add links in sortByLatency[] order) */
2322
	/* Find the interval we need (add links in sortByLatency[] order) */
2323
	for (numFragments = 1;
2323
	for (numFragments = 1;
Lines 2401-2407 ng_ppp_mp_strategy(node_p node, int len, int *distrib) Link Here
2401
 * Compare two integers
2401
 * Compare two integers
2402
 */
2402
 */
2403
static int
2403
static int
2404
ng_ppp_intcmp(void *latency, const void *v1, const void *v2)
2404
ng_ppp_intcmp(const void *v1, const void *v2, void *latency)
2405
{
2405
{
2406
	const int index1 = *((const int *) v1);
2406
	const int index1 = *((const int *) v1);
2407
	const int index2 = *((const int *) v2);
2407
	const int index2 = *((const int *) v2);
(-)b/sys/sys/libkern.h (-3 / +2 lines)
Lines 163-170 void *memcchr(const void *s, int c, size_t n); Link Here
163
void	*memmem(const void *l, size_t l_len, const void *s, size_t s_len);
163
void	*memmem(const void *l, size_t l_len, const void *s, size_t s_len);
164
void	 qsort(void *base, size_t nmemb, size_t size,
164
void	 qsort(void *base, size_t nmemb, size_t size,
165
	    int (*compar)(const void *, const void *));
165
	    int (*compar)(const void *, const void *));
166
void	 qsort_r(void *base, size_t nmemb, size_t size, void *thunk,
166
void	 qsort_r(void *base, size_t nmemb, size_t size,
167
	    int (*compar)(void *, const void *, const void *));
167
	    int (*compar)(const void *, const void *, void *), void *thunk);
168
u_long	 random(void);
168
u_long	 random(void);
169
int	 scanc(u_int, const u_char *, const u_char *, int);
169
int	 scanc(u_int, const u_char *, const u_char *, int);
170
int	 strcasecmp(const char *, const char *);
170
int	 strcasecmp(const char *, const char *);
171
- 

Return to bug 266227