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: isamwrite.c /main/3 1995/10/23 11:35:14 rswiston $ */
29 static char sccsid[] = "@(#)isamwrite.c 1.6 89/07/17 Copyr 1988 Sun Micro";
32 * Copyright (c) 1988 by Sun Microsystems, Inc.
38 * Description: _amwrite()
39 * Write record to ISAM file.
44 #include "isam_impl.h"
46 static int _addkeys2 ();
47 extern long *ismaxlong;
50 * _amwrite(isfhandle, record, reclen, curpos,
53 * _amwrite() writes a new record to ISAM file.
56 * isfhandle Handle of ISAM file
58 * reclen length of the record
59 * curpos current record position
62 * curpos new current position
63 * recnum record number
64 * errcode error status of the operation
69 _amwrite(Bytearray *isfhandle, char *record, int reclen,
70 Bytearray *curpos, Recno *recnum, struct errcode *errcode)
81 * Get FCB corresponding to the isfhandle handle.
83 if ((fcb = _openfcb(isfhandle, errcode)) == NULL) {
88 rec_write = (fcb->varflag?_vlrec_write:_flrec_write);
91 * Update information in FCB from CNTL page on the disk
93 (void)_isfcb_cntlpg_r2(fcb);
95 if (rec_write(fcb, record, &recnum2, reclen) == ISERROR) {
96 _isfatal_error("_amwrite() cannot write record");
102 if ((err = _addkeys2(fcb, record, recnum2, curpos)) != ISOK) {
103 _amseterrcode(errcode, err);
110 _amseterrcode(errcode, ISOK);
118 * Return new current record position.
120 crp = (Crp *) curpos->data;
123 crp->recno = recnum2;
126 * Update CNTL Page from the FCB.
128 (void)_isfcb_cntlpg_w2(fcb);
140 * If error is not EDUPL position undefined.
142 if (errcode->iserrno != EDUPL) {
143 ((Crp *)curpos->data)->flag = CRP_UNDEF;
147 * Restore FCB from CNTL page.
149 if (fcb) (void)_isfcb_cntlpg_r2(fcb);
159 * Insert key entry to all indexes.
161 * Returns ISOK, or EDUPS.
164 int _addkeys (Fcb *fcb, char *record, Recno recnum)
166 int nkeys = fcb->nkeys;
170 for (i = 0; i < nkeys; i++) {
171 if ((err = _add1key(fcb, fcb->keys + i, record, recnum,
172 (char*)NULL)) != ISOK)
180 _addkeys2 (Fcb *fcb, char *record, Recno recnum, Bytearray *curpos)
182 int nkeys = fcb->nkeys;
189 crp = (Crp *)curpos->data;
192 for (i = 0; i < nkeys; i++) {
193 keydesc2 = fcb->keys + i;
194 if ((err =_add1key(fcb, keydesc2, record, recnum,
195 (keydesc2->k2_keyid == keyid) ?
196 crp->key : (char *) NULL)) != ISOK)