lib/tt/mini_isam: remove register keyword
[oweals/cde.git] / cde / lib / tt / mini_isam / isdelcurr.c
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: isdelcurr.c /main/3 1995/10/23 11:37:32 rswiston $                                                   */
28 #ifndef lint
29 static char sccsid[] = "@(#)isdelcurr.c 1.8 89/07/17 Copyr 1988 Sun Micro";
30 #endif
31 /*
32  * Copyright (c) 1988 by Sun Microsystems, Inc.
33  */
34
35 /*
36  * isdelcurr.c
37  *
38  * Description:
39  *      Delete current record from ISAM file. 
40  */
41
42
43 #include "isam_impl.h"
44 #include <sys/time.h>
45
46 static int _amdelcurr();
47
48 /*
49  * err = isdelcurr(isfd, record)
50  *
51  * Isdelcurr() modifies the current record in ISAM file. 
52  * All indexes of the ISAM file are updated.
53  *
54  * Current record position is not changed.
55  * isrecnum is set to to the deleted record.
56  *
57  * Returns 0 if successful, or -1 of any error.
58  *
59  * Errors:
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.
65  */
66
67 int 
68 isdelcurr(int isfd)
69 {
70     int                 _am_delcurr();
71     Fab *fab;
72     int                 ret;
73     int                 recnum;
74
75     /*
76      * Get File Access Block.
77      */
78     if ((fab = _isfd_find(isfd)) == NULL) {
79         _setiserrno2(ENOTOPEN, '9', '0');
80         return (ISERROR);
81     }
82
83     /*
84      * Check that the open mode was  ISINOUT.
85      */
86     if (fab->openmode != OM_INOUT) {
87         _setiserrno2(ENOTOPEN, '9', '0');
88         return (ISERROR);
89     }
90
91     if ((ret = _amdelcurr(&fab->isfhandle, &fab->curpos,
92                           &recnum, &fab->errcode)) == ISOK) {
93         isrecnum = recnum;                   /* Set isrecnum */
94     }
95
96     _seterr_errcode(&fab->errcode);
97
98     return (ret);                            /* Successful write */
99 }
100
101 /*
102  * _amdelcurr(isfhandle, curpos, recnum, errcode)
103  *
104  * _amdelcurr() deletes a record from ISAM file.
105  *
106  * Input params:
107  *      isfhandle       Handle of ISAM file
108  *      curpos          Curent record position
109  *
110  * Output params:
111  *      recnum          record number of the deleted record
112  *      errcode         error status of the operation
113  *
114  */
115
116 static int
117 _amdelcurr(Bytearray *isfhandle, Bytearray *curpos, Recno *recnum,
118            struct errcode *errcode)
119 {
120     Fcb                 *fcb = NULL;
121     Crp                 *crp;
122     char                recbuf[ISMAXRECLEN];
123     int                 reclen;
124     int                 (*rec_read)();
125     int                 (*rec_delete)();
126
127     _isam_entryhook();
128
129     /*
130      * Get FCB corresponding to the isfhandle handle.
131      */
132     if ((fcb = _openfcb(isfhandle, errcode)) == NULL) {
133         _isam_exithook();
134         return (ISERROR);
135     }
136
137     rec_read = (fcb->varflag?_vlrec_read:_flrec_read);
138     rec_delete = (fcb->varflag?_vlrec_delete:_flrec_delete);
139
140     /*
141      * Get info from current record position structure.
142      */
143     crp = (Crp *) curpos->data;
144
145     if (crp->flag != CRP_ON) {
146         _amseterrcode(errcode, ENOCURR);
147         goto ERROR;
148     }
149
150     /*
151      * Update information in FCB from CNTL page on the disk
152      */
153     (void)_isfcb_cntlpg_r2(fcb);
154
155     /*
156      * We must read the record first to be able to delete keys.
157      */
158     if (rec_read(fcb, recbuf, crp->recno, &reclen) != ISOK) {
159         _amseterrcode(errcode, ENOCURR);
160         goto ERROR;
161     }
162
163     if (rec_delete(fcb, crp->recno) != ISOK) {
164         _amseterrcode(errcode, ENOCURR);
165         goto ERROR;
166     }
167
168     *recnum = crp->recno;
169
170     fcb->nrecords--;
171
172     /*
173      * Delete associated entries from all indexes.
174      */
175     _delkeys(fcb, recbuf, crp->recno);
176
177     _amseterrcode(errcode, ISOK);
178
179     _issignals_mask();
180     _isdisk_commit();
181     _isdisk_sync();
182     _isdisk_inval();
183
184     /*
185      * Update CNTL Page from the FCB.
186      */
187     (void)_isfcb_cntlpg_w2(fcb);
188     _issignals_unmask();
189
190     _isam_exithook();
191     return (ISOK);
192
193  ERROR:
194     _isdisk_rollback();
195     _isdisk_inval();
196
197     /*
198      * Restore FCB from CNTL page.
199      */
200     if (fcb) (void)_isfcb_cntlpg_r2(fcb);
201
202     _isam_exithook();
203     return (ISERROR);
204 }
205
206
207
208