. pci driver now returns devices, even when they have been pci_reserve()d
[minix3.git] / lib / other / lsearch.c
blob8f834ce588e685e78a84158f90ad94d1779700d5
1 #include <lib.h>
2 #include <string.h>
3 /* lsearch(3) and lfind(3)
5 * Author: Terrence W. Holm Sep. 1988
6 */
8 #include <stddef.h>
10 _PROTOTYPE( char *lsearch, (char *key, char *base,
11 unsigned *count, unsigned width,
12 int (*keycmp)(const void *, const void *)));
13 _PROTOTYPE( char *lfind, (char *key, char *base,
14 unsigned *count, unsigned width,
15 int (*keycmp)(const void *, const void *)));
17 char *lsearch(key, base, count, width, keycmp)
18 char *key;
19 char *base;
20 unsigned *count;
21 unsigned width;
22 _PROTOTYPE( int (*keycmp), (const void *, const void *));
24 char *entry;
25 char *last = base + *count * width;
27 for (entry = base; entry < last; entry += width)
28 if (keycmp(key, entry) == 0) return(entry);
30 bcopy(key, last, width);
31 *count += 1;
32 return(last);
36 char *lfind(key, base, count, width, keycmp)
37 char *key;
38 char *base;
39 unsigned *count;
40 unsigned width;
41 _PROTOTYPE( int (*keycmp), (const void *, const void *));
43 char *entry;
44 char *last = base + *count * width;
46 for (entry = base; entry < last; entry += width)
47 if (keycmp(key, entry) == 0) return(entry);
49 return((char *)NULL);