8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / lib / libbc / libc / gen / common / tfind.c
blobb58036f1bd193b931bcd001f2fe5545605b267bf
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
7 * with the License.
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
20 * CDDL HEADER END
22 /* Copyright (c) 1984 AT&T */
23 /* All Rights Reserved */
25 #pragma ident "%Z%%M% %I% %E% SMI" /* from S5R2 1.2 */
27 /*LINTLIBRARY*/
29 * Tree search algorithm, generalized from Knuth (6.2.2) Algorithm T.
31 * The NODE * arguments are declared in the lint files as char *,
32 * because the definition of NODE isn't available to the user.
35 #include <search.h>
36 typedef char *POINTER;
37 typedef struct node { POINTER key; struct node *llink, *rlink; } NODE;
39 #define NULL 0
42 /* tfind - find a node, or return 0 */
43 NODE *
44 tfind(key, rootp, compar)
45 POINTER key; /* Key to be located */
46 register NODE **rootp; /* Address of the root of the tree */
47 int (*compar)(); /* Comparison function */
49 if (rootp == NULL)
50 return (NULL);
51 while (*rootp != NULL) { /* T1: */
52 int r = (*compar)(key, (*rootp)->key); /* T2: */
53 if (r == 0)
54 return (*rootp); /* Key found */
55 rootp = (r < 0) ?
56 &(*rootp)->llink : /* T3: Take left branch */
57 &(*rootp)->rlink; /* T4: Take right branch */
59 return (NODE *)(NULL);