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: isdelcurr.c /main/3 1995/10/23 11:37:32 rswiston $ */
29 * Copyright (c) 1988 by Sun Microsystems, Inc.
36 * Delete current record from ISAM file.
40 #include "isam_impl.h"
43 static int _amdelcurr();
46 * err = isdelcurr(isfd, record)
48 * Isdelcurr() modifies the current record in ISAM file.
49 * All indexes of the ISAM file are updated.
51 * Current record position is not changed.
52 * isrecnum is set to to the deleted record.
54 * Returns 0 if successful, or -1 of any error.
57 * ELOCKED The record or file has been locked by another process.
58 * ENOTOPEN isfd does not correspond to an open ISAM file, or the
59 * ISAM file was not opened with ISINOUT mode.
60 * ENOCURR Record with record number recnum does not exist, or it
61 * was deleted by another process.
73 * Get File Access Block.
75 if ((fab = _isfd_find(isfd)) == NULL) {
76 _setiserrno2(ENOTOPEN, '9', '0');
81 * Check that the open mode was ISINOUT.
83 if (fab->openmode != OM_INOUT) {
84 _setiserrno2(ENOTOPEN, '9', '0');
88 if ((ret = _amdelcurr(&fab->isfhandle, &fab->curpos,
89 &recnum, &fab->errcode)) == ISOK) {
90 isrecnum = recnum; /* Set isrecnum */
93 _seterr_errcode(&fab->errcode);
95 return (ret); /* Successful write */
99 * _amdelcurr(isfhandle, curpos, recnum, errcode)
101 * _amdelcurr() deletes a record from ISAM file.
104 * isfhandle Handle of ISAM file
105 * curpos Curent record position
108 * recnum record number of the deleted record
109 * errcode error status of the operation
114 _amdelcurr(Bytearray *isfhandle, Bytearray *curpos, Recno *recnum,
115 struct errcode *errcode)
119 char recbuf[ISMAXRECLEN];
127 * Get FCB corresponding to the isfhandle handle.
129 if ((fcb = _openfcb(isfhandle, errcode)) == NULL) {
134 rec_read = (fcb->varflag?_vlrec_read:_flrec_read);
135 rec_delete = (fcb->varflag?_vlrec_delete:_flrec_delete);
138 * Get info from current record position structure.
140 crp = (Crp *) curpos->data;
142 if (crp->flag != CRP_ON) {
143 _amseterrcode(errcode, ENOCURR);
148 * Update information in FCB from CNTL page on the disk
150 (void)_isfcb_cntlpg_r2(fcb);
153 * We must read the record first to be able to delete keys.
155 if (rec_read(fcb, recbuf, crp->recno, &reclen) != ISOK) {
156 _amseterrcode(errcode, ENOCURR);
160 if (rec_delete(fcb, crp->recno) != ISOK) {
161 _amseterrcode(errcode, ENOCURR);
165 *recnum = crp->recno;
170 * Delete associated entries from all indexes.
172 _delkeys(fcb, recbuf, crp->recno);
174 _amseterrcode(errcode, ISOK);
182 * Update CNTL Page from the FCB.
184 (void)_isfcb_cntlpg_w2(fcb);
195 * Restore FCB from CNTL page.
197 if (fcb) (void)_isfcb_cntlpg_r2(fcb);