summaryrefslogtreecommitdiff
path: root/src/lib/libc/stdlib/qsort.c
diff options
context:
space:
mode:
authorpat <>2005-03-30 18:51:49 +0000
committerpat <>2005-03-30 18:51:49 +0000
commit894b6ab0099e7d9ca2ad9acb75246cd0a4542167 (patch)
treef9fb8e9324f6cbdc10d72cab8b889d470252465a /src/lib/libc/stdlib/qsort.c
parent162f8b042bf31ab94714a6f194e9836c08c085f5 (diff)
downloadopenbsd-894b6ab0099e7d9ca2ad9acb75246cd0a4542167.tar.gz
openbsd-894b6ab0099e7d9ca2ad9acb75246cd0a4542167.tar.bz2
openbsd-894b6ab0099e7d9ca2ad9acb75246cd0a4542167.zip
ansi + de-register
ok otto deraadt
Diffstat (limited to 'src/lib/libc/stdlib/qsort.c')
-rw-r--r--src/lib/libc/stdlib/qsort.c25
1 files changed, 9 insertions, 16 deletions
diff --git a/src/lib/libc/stdlib/qsort.c b/src/lib/libc/stdlib/qsort.c
index 2a972c0eb0..154c51a86c 100644
--- a/src/lib/libc/stdlib/qsort.c
+++ b/src/lib/libc/stdlib/qsort.c
@@ -28,13 +28,13 @@
28 */ 28 */
29 29
30#if defined(LIBC_SCCS) && !defined(lint) 30#if defined(LIBC_SCCS) && !defined(lint)
31static char *rcsid = "$OpenBSD: qsort.c,v 1.8 2003/06/02 20:18:38 millert Exp $"; 31static char *rcsid = "$OpenBSD: qsort.c,v 1.9 2005/03/30 18:51:49 pat Exp $";
32#endif /* LIBC_SCCS and not lint */ 32#endif /* LIBC_SCCS and not lint */
33 33
34#include <sys/types.h> 34#include <sys/types.h>
35#include <stdlib.h> 35#include <stdlib.h>
36 36
37static __inline char *med3(char *, char *, char *, int (*)()); 37static __inline char *med3(char *, char *, char *, int (*)(const void *, const void *));
38static __inline void swapfunc(char *, char *, int, int); 38static __inline void swapfunc(char *, char *, int, int);
39 39
40#define min(a, b) (a) < (b) ? a : b 40#define min(a, b) (a) < (b) ? a : b
@@ -44,10 +44,10 @@ static __inline void swapfunc(char *, char *, int, int);
44 */ 44 */
45#define swapcode(TYPE, parmi, parmj, n) { \ 45#define swapcode(TYPE, parmi, parmj, n) { \
46 long i = (n) / sizeof (TYPE); \ 46 long i = (n) / sizeof (TYPE); \
47 register TYPE *pi = (TYPE *) (parmi); \ 47 TYPE *pi = (TYPE *) (parmi); \
48 register TYPE *pj = (TYPE *) (parmj); \ 48 TYPE *pj = (TYPE *) (parmj); \
49 do { \ 49 do { \
50 register TYPE t = *pi; \ 50 TYPE t = *pi; \
51 *pi++ = *pj; \ 51 *pi++ = *pj; \
52 *pj++ = t; \ 52 *pj++ = t; \
53 } while (--i > 0); \ 53 } while (--i > 0); \
@@ -57,9 +57,7 @@ static __inline void swapfunc(char *, char *, int, int);
57 es % sizeof(long) ? 2 : es == sizeof(long)? 0 : 1; 57 es % sizeof(long) ? 2 : es == sizeof(long)? 0 : 1;
58 58
59static __inline void 59static __inline void
60swapfunc(a, b, n, swaptype) 60swapfunc(char *a, char *b, int n, int swaptype)
61 char *a, *b;
62 int n, swaptype;
63{ 61{
64 if (swaptype <= 1) 62 if (swaptype <= 1)
65 swapcode(long, a, b, n) 63 swapcode(long, a, b, n)
@@ -78,9 +76,7 @@ swapfunc(a, b, n, swaptype)
78#define vecswap(a, b, n) if ((n) > 0) swapfunc(a, b, n, swaptype) 76#define vecswap(a, b, n) if ((n) > 0) swapfunc(a, b, n, swaptype)
79 77
80static __inline char * 78static __inline char *
81med3(a, b, c, cmp) 79med3(char *a, char *b, char *c, int (*cmp)(const void *, const void *))
82 char *a, *b, *c;
83 int (*cmp)();
84{ 80{
85 return cmp(a, b) < 0 ? 81 return cmp(a, b) < 0 ?
86 (cmp(b, c) < 0 ? b : (cmp(a, c) < 0 ? c : a )) 82 (cmp(b, c) < 0 ? b : (cmp(a, c) < 0 ? c : a ))
@@ -88,14 +84,11 @@ med3(a, b, c, cmp)
88} 84}
89 85
90void 86void
91qsort(aa, n, es, cmp) 87qsort(void *aa, size_t n, size_t es, int (*cmp)(const void *, const void *))
92 void *aa;
93 size_t n, es;
94 int (*cmp)();
95{ 88{
96 char *pa, *pb, *pc, *pd, *pl, *pm, *pn; 89 char *pa, *pb, *pc, *pd, *pl, *pm, *pn;
97 int d, r, swaptype, swap_cnt; 90 int d, r, swaptype, swap_cnt;
98 register char *a = aa; 91 char *a = aa;
99 92
100loop: SWAPINIT(a, es); 93loop: SWAPINIT(a, es);
101 swap_cnt = 0; 94 swap_cnt = 0;