1 /*
2 * libhfs - library for reading and writing Macintosh HFS volumes
3 * Copyright (C) 1996-1998 Robert Leslie
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
18 * MA 02110-1301, USA.
19 *
20 * $Id: node.c,v 1.9 1998/11/02 22:09:05 rob Exp $
21 */
22
23 #include "config.h"
24 #include "libhfs.h"
25 #include "node.h"
26 #include "data.h"
27 #include "btree.h"
28
29 /*
30 * NAME: node->search()
31 * DESCRIPTION: locate a record in a node, or the record it should follow
32 */
n_search(node * np,const byte * pkey)33 int n_search(node *np, const byte *pkey)
34 {
35 const btree *bt = np->bt;
36 byte key1[HFS_MAX_KEYLEN], key2[HFS_MAX_KEYLEN];
37 int i, comp = -1;
38
39 bt->keyunpack(pkey, key2);
40
41 for (i = np->nd.ndNRecs; i--; )
42 {
43 const byte *rec;
44
45 rec = HFS_NODEREC(*np, i);
46
47 if (HFS_RECKEYLEN(rec) == 0)
48 continue; /* deleted record */
49
50 bt->keyunpack(rec, key1);
51 comp = bt->keycompare(key1, key2);
52
53 if (comp <= 0)
54 break;
55 }
56
57 np->rnum = i;
58
59 return comp == 0;
60 }
61