isamdelrec.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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: isamdelrec.c /main/3 1995/10/23 11:34:30 rswiston $ */
  28. /*
  29. * Copyright (c) 1988 by Sun Microsystems, Inc.
  30. */
  31. /*
  32. * isamdelrec.c
  33. *
  34. * Description: _amdelrec()
  35. * Delete record from ISAM file.
  36. *
  37. *
  38. */
  39. #include "isam_impl.h"
  40. void _delkeys();
  41. /*
  42. * _amdelrec(isfhandle, recnum, errcode)
  43. *
  44. * _amdelrec() deletes a record from ISAM file.
  45. *
  46. * Input params:
  47. * isfhandle Handle of ISAM file
  48. * recnum record number of the record to be deleted
  49. *
  50. * Output params:
  51. * errcode error status of the operation
  52. *
  53. */
  54. int
  55. _amdelrec(Bytearray *isfhandle, Recno recnum, struct errcode *errcode)
  56. {
  57. Fcb *fcb = NULL;
  58. char recbuf[ISMAXRECLEN];
  59. int reclen;
  60. int (*rec_read)();
  61. int (*rec_delete)();
  62. _isam_entryhook();
  63. /*
  64. * Get FCB corresponding to the isfhandle handle.
  65. */
  66. if ((fcb = _openfcb(isfhandle, errcode)) == NULL) {
  67. _isam_exithook();
  68. return (ISERROR);
  69. }
  70. rec_read = (fcb->varflag?_vlrec_read:_flrec_read);
  71. rec_delete = (fcb->varflag?_vlrec_delete:_flrec_delete);
  72. /*
  73. * Update information in FCB from CNTL page on the disk
  74. */
  75. (void)_isfcb_cntlpg_r2(fcb);
  76. /*
  77. * We must read the record first to be able to delete keys.
  78. */
  79. if (rec_read(fcb, recbuf, recnum, &reclen) != ISOK) {
  80. _amseterrcode(errcode, ENOREC);
  81. goto ERROR;
  82. }
  83. if (rec_delete(fcb, recnum) != ISOK) {
  84. _amseterrcode(errcode, ENOREC);
  85. goto ERROR;
  86. }
  87. fcb->nrecords--;
  88. /*
  89. * Delete associated entries from all indexes.
  90. */
  91. _delkeys(fcb, recbuf, recnum);
  92. _amseterrcode(errcode, ISOK);
  93. _issignals_mask();
  94. _isdisk_commit();
  95. _isdisk_sync();
  96. _isdisk_inval();
  97. /*
  98. * Update CNTL Page from the FCB.
  99. */
  100. (void)_isfcb_cntlpg_w2(fcb);
  101. _issignals_unmask();
  102. _isam_exithook();
  103. return (ISOK);
  104. ERROR:
  105. _isdisk_rollback();
  106. _isdisk_inval();
  107. /*
  108. * Restore FCB from CNTL page.
  109. */
  110. if (fcb) (void)_isfcb_cntlpg_r2(fcb);
  111. _isam_exithook();
  112. return (ISERROR);
  113. }
  114. /*
  115. * _isdelkeys()
  116. *
  117. * Delete key entry from all indexes.
  118. */
  119. void
  120. _delkeys(Fcb *fcb, char *record, Recno recnum)
  121. {
  122. int nkeys = fcb->nkeys;
  123. int i;
  124. for (i = 0; i < nkeys; i++) {
  125. _del1key(fcb, fcb->keys + i, record, recnum);
  126. }
  127. }