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