|
Last change
on this file since 2425 was 2177, checked in by sandervl, 26 years ago |
|
all crt functions moved to crtdll
|
|
File size:
901 bytes
|
| Line | |
|---|
| 1 | /* $Id: bsearch.c,v 1.2 1999-12-21 12:27:11 sandervl Exp $ */
|
|---|
| 2 | /* bsearch.c (emx+gcc) -- Copyright (c) 1990-1995 by Eberhard Mattes */
|
|---|
| 3 |
|
|---|
| 4 | #include <odin.h>
|
|---|
| 5 | #include <builtin.h>
|
|---|
| 6 |
|
|---|
| 7 | /*********************************************************************
|
|---|
| 8 | * bsearch (CRTDLL.346)
|
|---|
| 9 | */
|
|---|
| 10 |
|
|---|
| 11 | void *CDECL CRTDLL_bsearch (const void *key, const void *base, size_t num, size_t width,
|
|---|
| 12 | int (* CDECL compare)(const void *key, const void *element))
|
|---|
| 13 | {
|
|---|
| 14 | int left, right, median, sign;
|
|---|
| 15 | const void *element;
|
|---|
| 16 |
|
|---|
| 17 | if (width == 0)
|
|---|
| 18 | return 0;
|
|---|
| 19 | left = 1; right = num;
|
|---|
| 20 | while (left <= right)
|
|---|
| 21 | {
|
|---|
| 22 | median = (left + right) / 2;
|
|---|
| 23 | element = (void *)((char *)base + (median-1)*width);
|
|---|
| 24 | sign = compare (key, element);
|
|---|
| 25 | if (sign == 0)
|
|---|
| 26 | return (void *)element;
|
|---|
| 27 | if (sign > 0)
|
|---|
| 28 | left = median + 1;
|
|---|
| 29 | else
|
|---|
| 30 | right = median - 1;
|
|---|
| 31 | }
|
|---|
| 32 | return 0;
|
|---|
| 33 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.