2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these libraries and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 /*%% (c) Copyright 1993, 1994 Hewlett-Packard Company */
24 /*%% (c) Copyright 1993, 1994 International Business Machines Corp. */
25 /*%% (c) Copyright 1993, 1994 Sun Microsystems, Inc. */
26 /*%% (c) Copyright 1993, 1994 Novell, Inc. */
27 /*%% $XConsortium: iskeyaux.c /main/3 1995/10/23 11:41:11 rswiston $ */
29 * Copyright (c) 1988 by Sun Microsystems, Inc.
37 * Auxiliary key related functions
40 #include "isam_impl.h"
42 Blkno _isgetfreekpage();
47 * Extract key parts from record buffer
51 _iskey_extract (Keydesc2 *pkeydesc2, char *recp, char *keyp)
54 struct keypart2 *ppart;
57 nparts = pkeydesc2->k2_nparts;
58 ppart = pkeydesc2->k2_part;
61 * XXX - This is a kludge to fix a problem with keys of an odd (ODD as
62 * not even) length that are extended to the nearest multiple of 2.
64 * It would be better to use bzero() here and not to call it in
65 * add1key etc. But this change was done just during the FCS process
66 * and may be robust even though it's not the cleanest thing under
70 keyp[pkeydesc2->k2_len - 1] = '\0';
72 for (i = 0; i < nparts; i++) {
73 memcpy( keyp + ppart->kp2_offset,recp + ppart->kp2_start,
82 * Allocate an initialize new key page.
84 * blkno, Output parameter
88 _allockpage(Fcb *fcb, int capac, int level, Blkno *blkno)
93 *blkno = _isindfreel_alloc(fcb);
95 /* Fix the block in cache */
96 pbufhdr = _isdisk_fix(fcb, fcb->indfd, *blkno, ISFIXNOREAD);
98 p = pbufhdr->isb_buffer;
100 memset(p, 0, ISPAGESIZE);
102 /* Mark page as B-tree page. */
103 stshort((short)PT_INDEX, p + BT_TYPE_OFF);
105 /* Store page capacity. */
106 stshort((short)capac, p + BT_CAPAC_OFF);
108 /* Store B-tree level. */
109 stshort((short)level, p + BT_LEVEL_OFF);