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