iskeyaux.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /*
  2. * CDE - Common Desktop Environment
  3. *
  4. * Copyright (c) 1993-2012, The Open Group. All rights reserved.
  5. *
  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)
  10. * any later version.
  11. *
  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
  16. * details.
  17. *
  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
  22. */
  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 $ */
  28. /*
  29. * Copyright (c) 1988 by Sun Microsystems, Inc.
  30. */
  31. /*
  32. * iskeyaux.c
  33. *
  34. * Description:
  35. * Auxiliary key related functions
  36. */
  37. #include "isam_impl.h"
  38. Blkno _isgetfreekpage();
  39. /*
  40. * _isindex_extract()
  41. *
  42. * Extract key parts from record buffer
  43. */
  44. void
  45. _iskey_extract (Keydesc2 *pkeydesc2, char *recp, char *keyp)
  46. {
  47. int i;
  48. struct keypart2 *ppart;
  49. int nparts;
  50. nparts = pkeydesc2->k2_nparts;
  51. ppart = pkeydesc2->k2_part;
  52. /*
  53. * XXX - This is a kludge to fix a problem with keys of an odd (ODD as
  54. * not even) length that are extended to the nearest multiple of 2.
  55. *
  56. * It would be better to use bzero() here and not to call it in
  57. * add1key etc. But this change was done just during the FCS process
  58. * and may be robust even though it's not the cleanest thing under
  59. * the sun.
  60. */
  61. keyp[pkeydesc2->k2_len - 1] = '\0';
  62. for (i = 0; i < nparts; i++) {
  63. memcpy( keyp + ppart->kp2_offset,recp + ppart->kp2_start,
  64. ppart->kp2_leng);
  65. ppart++;
  66. }
  67. }
  68. /*
  69. * _allockpage()
  70. *
  71. * Allocate an initialize new key page.
  72. *
  73. * blkno, Output parameter
  74. */
  75. Bufhdr *
  76. _allockpage(Fcb *fcb, int capac, int level, Blkno *blkno)
  77. {
  78. Bufhdr *pbufhdr;
  79. char *p;
  80. *blkno = _isindfreel_alloc(fcb);
  81. /* Fix the block in cache */
  82. pbufhdr = _isdisk_fix(fcb, fcb->indfd, *blkno, ISFIXNOREAD);
  83. p = pbufhdr->isb_buffer;
  84. memset(p, 0, ISPAGESIZE);
  85. /* Mark page as B-tree page. */
  86. stshort((short)PT_INDEX, p + BT_TYPE_OFF);
  87. /* Store page capacity. */
  88. stshort((short)capac, p + BT_CAPAC_OFF);
  89. /* Store B-tree level. */
  90. stshort((short)level, p + BT_LEVEL_OFF);
  91. return (pbufhdr);
  92. }