summaryrefslogtreecommitdiff
path: root/libc/stdlib/bsearch.c
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2000-10-09 20:06:30 +0000
committerEric Andersen <andersen@codepoet.org>2000-10-09 20:06:30 +0000
commitc1fe19d4c1db610692365472a90f4661e48449c1 (patch)
treed0b0219ffca3c4c4256f55c4aea4513e43d6aecd /libc/stdlib/bsearch.c
parent9efafb8bbc7408b04643dcd53825d971577b4d9d (diff)
Bug ugly formatting update
Diffstat (limited to 'libc/stdlib/bsearch.c')
-rw-r--r--libc/stdlib/bsearch.c56
1 files changed, 26 insertions, 30 deletions
diff --git a/libc/stdlib/bsearch.c b/libc/stdlib/bsearch.c
index 72ba2617a..04d5ab68b 100644
--- a/libc/stdlib/bsearch.c
+++ b/libc/stdlib/bsearch.c
@@ -10,37 +10,33 @@
*/
#include <stdio.h>
-static int _bsearch; /* index of element found, or where to
- * insert */
+static int _bsearch; /* index of element found, or where to
-char *
-bsearch(key, base, num, size, cmp)
-register char *key; /* item to search for */
-register char *base; /* base address */
-int num; /* number of elements */
-register int size; /* element size in bytes */
-register int (*cmp) (); /* comparison function */
+ * insert */
+
+char *bsearch(key, base, num, size, cmp)
+register char *key; /* item to search for */
+register char *base; /* base address */
+int num; /* number of elements */
+register int size; /* element size in bytes */
+register int (*cmp) (); /* comparison function */
{
- register int a, b, c, dir;
+ register int a, b, c, dir;
- a = 0;
- b = num - 1;
- while (a <= b)
- {
- c = (a + b) >> 1; /* == ((a + b) / 2) */
- if ((dir = (*cmp) ((base + (c * size)), key)))
- {
- if (dir > 0)
- b = c - 1;
- else /* (dir < 0) */
- a = c + 1;
- }
- else
- {
- _bsearch = c;
- return (base + (c * size));
- }
- }
- _bsearch = b;
- return (NULL);
+ a = 0;
+ b = num - 1;
+ while (a <= b) {
+ c = (a + b) >> 1; /* == ((a + b) / 2) */
+ if ((dir = (*cmp) ((base + (c * size)), key))) {
+ if (dir > 0)
+ b = c - 1;
+ else /* (dir < 0) */
+ a = c + 1;
+ } else {
+ _bsearch = c;
+ return (base + (c * size));
+ }
+ }
+ _bsearch = b;
+ return (NULL);
}