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: iswrite.c /main/3 1995/10/23 11:46:15 rswiston $ */
29 * Copyright (c) 1988 by Sun Microsystems, Inc.
36 * Write a record to ISAM file.
40 #include "isam_impl.h"
44 static int _am_write();
47 * err = iswrite(isfd, record)
49 * Iswrite() adds a new record to an ISAM file. All indexes of the ISAM
52 * Current record position is not changed.
53 * isrecnum is set to indicate the new record.
55 * If the ISAM file is for variable length records, the isreclen variable
56 * must be set to indicate the actual length of the record, which must
57 * be between the minimum and maximum length, as specified in isbuild().
59 * Returns 0 if successful, or -1 of any error.
62 * EDUPL The write woul result in a duplicate on a key that
63 * does not allow duplicates.
64 * ELOCKED The file has been locked by another process.
65 * ENOTOPEN isfd does not correspond to an open ISAM file, or the
66 * ISAM file was opened with ISINPUT mode.
67 * EBADARG Unacceptable value of isreclen for variable length record.
71 iswrite(int isfd, char *record)
81 * Get File Access Block.
83 if ((fab = _isfd_find(isfd)) == NULL) {
84 _setiserrno2(ENOTOPEN, '9', '0');
89 * Check that the open mode was ISOUTPUT, or ISINOUT.
91 if (fab->openmode != OM_OUTPUT && fab->openmode != OM_INOUT) {
92 _setiserrno2(ENOTOPEN, '9', '0');
97 * Determine record length. Check it against min and max record length.
99 reclen = (fab->varlength == TRUE) ? isreclen : fab->minreclen;
100 if (reclen < fab->minreclen || reclen > fab->maxreclen) {
101 _setiserrno2(EBADARG, '9', '0');
106 * Call the Access Method
108 curpos = _bytearr_dup(&fab->curpos);
110 if ((ret = _am_write(fab, record, reclen, &curpos, &recnum)) == ISOK) {
111 isrecnum = recnum; /* Set isrecnum */
113 _bytearr_free(&curpos);
115 _seterr_errcode(&fab->errcode);
117 return (ret); /* Successful write */
121 Static int _am_write(Fab *fab, char *record, int reclen,
122 Bytearray *curpos, Recno *recnum)
124 return (_amwrite(&fab->isfhandle, record, reclen,
125 curpos, recnum, &fab->errcode));