source: trunk/minix/lib/other/lsearch.c@ 10

Last change on this file since 10 was 9, checked in by Mattia Monga, 14 years ago

Minix 3.1.2a

File size: 1.1 KB
RevLine 
[9]1#include <lib.h>
2#include <string.h>
3/* lsearch(3) and lfind(3)
4 *
5 * Author: Terrence W. Holm Sep. 1988
6 */
7
8#include <stddef.h>
9
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 *)));
16
17char *lsearch(key, base, count, width, keycmp)
18char *key;
19char *base;
20unsigned *count;
21unsigned width;
22_PROTOTYPE( int (*keycmp), (const void *, const void *));
23{
24 char *entry;
25 char *last = base + *count * width;
26
27 for (entry = base; entry < last; entry += width)
28 if (keycmp(key, entry) == 0) return(entry);
29
30 bcopy(key, last, width);
31 *count += 1;
32 return(last);
33}
34
35
36char *lfind(key, base, count, width, keycmp)
37char *key;
38char *base;
39unsigned *count;
40unsigned width;
41_PROTOTYPE( int (*keycmp), (const void *, const void *));
42{
43 char *entry;
44 char *last = base + *count * width;
45
46 for (entry = base; entry < last; entry += width)
47 if (keycmp(key, entry) == 0) return(entry);
48
49 return((char *)NULL);
50}
Note: See TracBrowser for help on using the repository browser.