1 |
michael |
3253 |
/* |
2 |
|
|
** Copyright (C) 2002 by Kevin L. Mitchell <klmitch@mit.edu> |
3 |
|
|
** |
4 |
|
|
** This library is free software; you can redistribute it and/or |
5 |
|
|
** modify it under the terms of the GNU Library General Public |
6 |
|
|
** License as published by the Free Software Foundation; either |
7 |
|
|
** version 2 of the License, or (at your option) any later version. |
8 |
|
|
** |
9 |
|
|
** This library is distributed in the hope that it will be useful, |
10 |
|
|
** but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 |
|
|
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
12 |
|
|
** Library General Public License for more details. |
13 |
|
|
** |
14 |
|
|
** You should have received a copy of the GNU Library General Public |
15 |
|
|
** License along with this library; if not, write to the Free |
16 |
|
|
** Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, |
17 |
|
|
** MA 02111-1307, USA |
18 |
|
|
** |
19 |
|
|
** @(#)$Id: ll_find.c,v 1.3 2006/07/13 05:36:16 klmitch Exp $ |
20 |
|
|
*/ |
21 |
|
|
/** \internal |
22 |
|
|
* \file |
23 |
|
|
* \brief Implementation of ll_find(). |
24 |
|
|
* |
25 |
|
|
* This file contains the implementation of the ll_find() function, |
26 |
|
|
* used to locate a specific element within a linked list. |
27 |
|
|
*/ |
28 |
|
|
#include "dbprim.h" |
29 |
|
|
#include "dbprim_int.h" |
30 |
|
|
|
31 |
|
|
RCSTAG("@(#)$Id: ll_find.c,v 1.3 2006/07/13 05:36:16 klmitch Exp $"); |
32 |
|
|
|
33 |
|
|
unsigned long |
34 |
|
|
ll_find(link_head_t *list, link_elem_t **elem_p, link_comp_t comp_func, |
35 |
|
|
link_elem_t *start, db_key_t *key) |
36 |
|
|
{ |
37 |
|
|
link_elem_t *elem; |
38 |
|
|
|
39 |
|
|
initialize_dbpr_error_table(); /* initialize error table */ |
40 |
|
|
|
41 |
|
|
/* Verify arguments */ |
42 |
|
|
if (!ll_verify(list) || !elem_p || !comp_func || !key || |
43 |
|
|
(start && !le_verify(start))) |
44 |
|
|
return DB_ERR_BADARGS; |
45 |
|
|
|
46 |
|
|
/* Verify that the start element is in this list */ |
47 |
|
|
if (start && list != start->le_head) |
48 |
|
|
return DB_ERR_WRONGTABLE; |
49 |
|
|
|
50 |
|
|
/* search the list... */ |
51 |
|
|
for (elem = start ? start : list->lh_first; elem; elem = elem->le_next) |
52 |
|
|
if (!(*comp_func)(key, elem->le_object)) { /* Compare... */ |
53 |
|
|
*elem_p = elem; /* comparison function must return "0" on match */ |
54 |
|
|
return 0; |
55 |
|
|
} |
56 |
|
|
|
57 |
|
|
return DB_ERR_NOENTRY; /* Couldn't find the element */ |
58 |
|
|
} |