Add GNU LGPL headers to all .c .C and .h files
[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 librararies 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(isfhandle, recnum, errcode)
64     Bytearray           *isfhandle;
65     Recno               recnum;
66     struct errcode      *errcode;
67 {
68     Fcb                 *fcb = NULL;
69     char                recbuf[ISMAXRECLEN];
70     int                 reclen;
71     int                 (*rec_read)();
72     int                 (*rec_delete)();
73
74     _isam_entryhook();
75
76     /*
77      * Get FCB corresponding to the isfhandle handle.
78      */
79     if ((fcb = _openfcb(isfhandle, errcode)) == NULL) {
80         _isam_exithook();
81         return (ISERROR);
82     }
83
84     rec_read = (fcb->varflag?_vlrec_read:_flrec_read);
85     rec_delete = (fcb->varflag?_vlrec_delete:_flrec_delete);
86
87     /*
88      * Update information in FCB from CNTL page on the disk
89      */
90     (void)_isfcb_cntlpg_r2(fcb);
91
92     /*
93      * We must read the record first to be able to delete keys.
94      */
95     if (rec_read(fcb, recbuf, recnum, &reclen) != ISOK) {
96         _amseterrcode(errcode, ENOREC);
97         goto ERROR;
98     }
99
100     if (rec_delete(fcb, recnum) != ISOK) {
101         _amseterrcode(errcode, ENOREC);
102         goto ERROR;
103     }
104
105     fcb->nrecords--;
106
107     /*
108      * Delete associated entries from all indexes.
109      */
110     _delkeys(fcb, recbuf, recnum);
111
112     _amseterrcode(errcode, ISOK);
113
114     _issignals_mask();
115     _isdisk_commit();
116     _isdisk_sync();
117     _isdisk_inval();
118
119     /*
120      * Update CNTL Page from the FCB.
121      */
122     (void)_isfcb_cntlpg_w2(fcb);
123     _issignals_unmask();
124
125     _isam_exithook();
126     return (ISOK);
127
128  ERROR:
129     _isdisk_rollback();
130     _isdisk_inval();
131
132     /*
133      * Restore FCB from CNTL page.
134      */
135     if (fcb) (void)_isfcb_cntlpg_r2(fcb);
136
137     _isam_exithook();
138     return (ISERROR);
139 }
140
141 /*
142  * _isdelkeys()
143  *
144  * Delete key entry from all indexes.
145  */
146
147 void
148 _delkeys(fcb, record, recnum)
149     register Fcb        *fcb;
150     char                *record;
151     Recno               recnum;
152 {
153     int                         nkeys = fcb->nkeys;
154     register int                i;
155
156     for (i = 0; i < nkeys; i++) {
157         _del1key(fcb, fcb->keys + i, record, recnum);
158     }
159 }      
160