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 librararies 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: iswrite.c /main/3 1995/10/23 11:46:15 rswiston $ */
29 static char sccsid[] = "@(#)iswrite.c 1.8 89/07/17 Copyr 1988 Sun Micro";
32 * Copyright (c) 1988 by Sun Microsystems, Inc.
39 * Write a record to ISAM file.
43 #include "isam_impl.h"
47 static int _am_write();
50 * err = iswrite(isfd, record)
52 * Iswrite() adds a new record to an ISAM file. All indexes of the ISAM
55 * Current record position is not changed.
56 * isrecnum is set to indicate the new record.
58 * If the ISAM file is for variable length records, the isreclen variable
59 * must be set to indicate the actual length of the record, which must
60 * be between the minimum and maximum length, as specified in isbuild().
62 * Returns 0 if successful, or -1 of any error.
65 * EDUPL The write woul result in a duplicate on a key that
66 * does not allow duplicates.
67 * ELOCKED The file has been locked by another process.
68 * ENOTOPEN isfd does not correspond to an open ISAM file, or the
69 * ISAM file was opened with ISINPUT mode.
70 * EBADARG Unacceptable value of isreclen for variable length record.
86 * Get File Access Block.
88 if ((fab = _isfd_find(isfd)) == NULL) {
89 _setiserrno2(ENOTOPEN, '9', '0');
94 * Check that the open mode was ISOUTPUT, or ISINOUT.
96 if (fab->openmode != OM_OUTPUT && fab->openmode != OM_INOUT) {
97 _setiserrno2(ENOTOPEN, '9', '0');
102 * Determine record length. Check it against min and max record length.
104 reclen = (fab->varlength == TRUE) ? isreclen : fab->minreclen;
105 if (reclen < fab->minreclen || reclen > fab->maxreclen) {
106 _setiserrno2(EBADARG, '9', '0');
111 * Call the Access Method
113 curpos = _bytearr_dup(&fab->curpos);
115 if ((ret = _am_write(fab, record, reclen, &curpos, &recnum)) == ISOK) {
116 isrecnum = recnum; /* Set isrecnum */
118 _bytearr_free(&curpos);
120 _seterr_errcode(&fab->errcode);
122 return (ret); /* Successful write */
126 Static int _am_write(fab, record, reclen, curpos, recnum)
133 return (_amwrite(&fab->isfhandle, record, reclen,
134 curpos, recnum, &fab->errcode));