Sync usage with man page.
[netbsd-mini2440.git] / usr.bin / make / lst.lib / lstFindFrom.c
blob034fcbe23c6e91e7d1b31db259e57a5d4e3e141e
1 /* $NetBSD: lstFindFrom.c,v 1.14 2009/01/23 21:26:30 dsl Exp $ */
3 /*
4 * Copyright (c) 1988, 1989, 1990, 1993
5 * The Regents of the University of California. All rights reserved.
7 * This code is derived from software contributed to Berkeley by
8 * Adam de Boor.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. Neither the name of the University nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE.
35 #ifndef MAKE_NATIVE
36 static char rcsid[] = "$NetBSD: lstFindFrom.c,v 1.14 2009/01/23 21:26:30 dsl Exp $";
37 #else
38 #include <sys/cdefs.h>
39 #ifndef lint
40 #if 0
41 static char sccsid[] = "@(#)lstFindFrom.c 8.1 (Berkeley) 6/6/93";
42 #else
43 __RCSID("$NetBSD: lstFindFrom.c,v 1.14 2009/01/23 21:26:30 dsl Exp $");
44 #endif
45 #endif /* not lint */
46 #endif
48 /*-
49 * LstFindFrom.c --
50 * Find a node on a list from a given starting point. Used by Lst_Find.
53 #include "lstInt.h"
55 /*-
56 *-----------------------------------------------------------------------
57 * Lst_FindFrom --
58 * Search for a node starting and ending with the given one on the
59 * given list using the passed datum and comparison function to
60 * determine when it has been found.
62 * Results:
63 * The found node or NULL
65 * Side Effects:
66 * None.
68 *-----------------------------------------------------------------------
70 LstNode
71 Lst_FindFrom(Lst l, LstNode ln, const void *d,
72 int (*cProc)(const void *, const void *))
74 ListNode tln;
76 if (!LstValid (l) || LstIsEmpty (l) || !LstNodeValid (ln, l)) {
77 return NULL;
80 tln = ln;
82 do {
83 if ((*cProc)(tln->datum, d) == 0)
84 return (tln);
85 tln = tln->nextPtr;
86 } while (tln != ln && tln != NULL);
88 return NULL;