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 static char sccsid[] = "@(#)isdelcurr.c 1.8 89/07/17 Copyr 1988 Sun Micro";
32 * Copyright (c) 1988 by Sun Microsystems, Inc.
39 * Delete current record from ISAM file.
43 #include "isam_impl.h"
46 static int _amdelcurr();
49 * err = isdelcurr(isfd, record)
51 * Isdelcurr() modifies the current record in ISAM file.
52 * All indexes of the ISAM file are updated.
54 * Current record position is not changed.
55 * isrecnum is set to to the deleted record.
57 * Returns 0 if successful, or -1 of any error.
60 * ELOCKED The record or file has been locked by another process.
61 * ENOTOPEN isfd does not correspond to an open ISAM file, or the
62 * ISAM file was not opened with ISINOUT mode.
63 * ENOCURR Record with record number recnum does not exist, or it
64 * was deleted by another process.
76 * Get File Access Block.
78 if ((fab = _isfd_find(isfd)) == NULL) {
79 _setiserrno2(ENOTOPEN, '9', '0');
84 * Check that the open mode was ISINOUT.
86 if (fab->openmode != OM_INOUT) {
87 _setiserrno2(ENOTOPEN, '9', '0');
91 if ((ret = _amdelcurr(&fab->isfhandle, &fab->curpos,
92 &recnum, &fab->errcode)) == ISOK) {
93 isrecnum = recnum; /* Set isrecnum */
96 _seterr_errcode(&fab->errcode);
98 return (ret); /* Successful write */
102 * _amdelcurr(isfhandle, curpos, recnum, errcode)
104 * _amdelcurr() deletes a record from ISAM file.
107 * isfhandle Handle of ISAM file
108 * curpos Curent record position
111 * recnum record number of the deleted record
112 * errcode error status of the operation
117 _amdelcurr(Bytearray *isfhandle, Bytearray *curpos, Recno *recnum,
118 struct errcode *errcode)
122 char recbuf[ISMAXRECLEN];
130 * Get FCB corresponding to the isfhandle handle.
132 if ((fcb = _openfcb(isfhandle, errcode)) == NULL) {
137 rec_read = (fcb->varflag?_vlrec_read:_flrec_read);
138 rec_delete = (fcb->varflag?_vlrec_delete:_flrec_delete);
141 * Get info from current record position structure.
143 crp = (Crp *) curpos->data;
145 if (crp->flag != CRP_ON) {
146 _amseterrcode(errcode, ENOCURR);
151 * Update information in FCB from CNTL page on the disk
153 (void)_isfcb_cntlpg_r2(fcb);
156 * We must read the record first to be able to delete keys.
158 if (rec_read(fcb, recbuf, crp->recno, &reclen) != ISOK) {
159 _amseterrcode(errcode, ENOCURR);
163 if (rec_delete(fcb, crp->recno) != ISOK) {
164 _amseterrcode(errcode, ENOCURR);
168 *recnum = crp->recno;
173 * Delete associated entries from all indexes.
175 _delkeys(fcb, recbuf, crp->recno);
177 _amseterrcode(errcode, ISOK);
185 * Update CNTL Page from the FCB.
187 (void)_isfcb_cntlpg_w2(fcb);
198 * Restore FCB from CNTL page.
200 if (fcb) (void)_isfcb_cntlpg_r2(fcb);