xref: /netbsd-src/external/cddl/osnet/sys/util/qsort.h (revision fc8ec0b896620494ee06c82427885881da50d528)
1*fc8ec0b8Shaad /*	$NetBSD: qsort.h,v 1.1 2009/08/07 20:57:58 haad Exp $	*/
2*fc8ec0b8Shaad 
3*fc8ec0b8Shaad /*-
4*fc8ec0b8Shaad  * Copyright (c) 2009 The NetBSD Foundation, Inc.
5*fc8ec0b8Shaad  * All rights reserved.
6*fc8ec0b8Shaad  *
7*fc8ec0b8Shaad  * This code is derived from software contributed to The NetBSD Foundation
8*fc8ec0b8Shaad  * by Andrew Doran.
9*fc8ec0b8Shaad  *
10*fc8ec0b8Shaad  * Redistribution and use in source and binary forms, with or without
11*fc8ec0b8Shaad  * modification, are permitted provided that the following conditions
12*fc8ec0b8Shaad  * are met:
13*fc8ec0b8Shaad  * 1. Redistributions of source code must retain the above copyright
14*fc8ec0b8Shaad  *    notice, this list of conditions and the following disclaimer.
15*fc8ec0b8Shaad  * 2. Redistributions in binary form must reproduce the above copyright
16*fc8ec0b8Shaad  *    notice, this list of conditions and the following disclaimer in the
17*fc8ec0b8Shaad  *    documentation and/or other materials provided with the distribution.
18*fc8ec0b8Shaad  *
19*fc8ec0b8Shaad  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20*fc8ec0b8Shaad  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21*fc8ec0b8Shaad  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22*fc8ec0b8Shaad  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23*fc8ec0b8Shaad  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24*fc8ec0b8Shaad  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25*fc8ec0b8Shaad  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26*fc8ec0b8Shaad  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27*fc8ec0b8Shaad  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28*fc8ec0b8Shaad  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29*fc8ec0b8Shaad  * POSSIBILITY OF SUCH DAMAGE.
30*fc8ec0b8Shaad  */
31*fc8ec0b8Shaad 
32*fc8ec0b8Shaad static inline void
qsort(void * base,size_t nmemb,size_t size,int (* compar)(const void *,const void *))33*fc8ec0b8Shaad qsort(void *base, size_t nmemb, size_t size,
34*fc8ec0b8Shaad          int (*compar)(const void *, const void *))
35*fc8ec0b8Shaad {
36*fc8ec0b8Shaad 	void *tmp;
37*fc8ec0b8Shaad 
38*fc8ec0b8Shaad 	tmp = kmem_alloc(size, KM_SLEEP);
39*fc8ec0b8Shaad 	kheapsort(base, nmemb, size, compar, tmp);
40*fc8ec0b8Shaad 	kmem_free(tmp, size);
41*fc8ec0b8Shaad }
42