lib/tt/mini_isam: remove register keyword
[oweals/cde.git] / cde / lib / tt / mini_isam / iswrite.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: iswrite.c /main/3 1995/10/23 11:46:15 rswiston $                                                     */
28 #ifndef lint
29 static char sccsid[] = "@(#)iswrite.c 1.8 89/07/17 Copyr 1988 Sun Micro";
30 #endif
31 /*
32  * Copyright (c) 1988 by Sun Microsystems, Inc.
33  */
34
35 /*
36  * iswrite.c
37  *
38  * Description:
39  *      Write a record to ISAM file. 
40  */
41
42
43 #include "isam_impl.h"
44 #include <sys/file.h>
45 #include <sys/time.h>
46
47 static int _am_write();
48
49 /*
50  * err =  iswrite(isfd, record)
51  *
52  * Iswrite() adds a new record to an ISAM file. All indexes of the ISAM
53  * file are updated.
54  *
55  * Current record position is not changed.
56  * isrecnum is set to indicate the new record.
57  *
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().
61  *
62  * Returns 0 if successful, or -1 of any error.
63  *
64  * Errors:
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.
71  */
72
73 int 
74 iswrite(int isfd, char *record)
75 {
76     int                 _am_write();
77     Fab *fab;
78     int                 reclen;
79     Recno               recnum;
80     Bytearray           curpos;
81     int                 ret;
82
83     /*
84      * Get File Access Block.
85      */
86     if ((fab = _isfd_find(isfd)) == NULL) {
87         _setiserrno2(ENOTOPEN, '9', '0');
88         return (ISERROR);
89     }
90
91     /*
92      * Check that the open mode was ISOUTPUT, or ISINOUT.
93      */
94     if (fab->openmode != OM_OUTPUT && fab->openmode != OM_INOUT) {
95         _setiserrno2(ENOTOPEN, '9', '0');
96         return (ISERROR);
97     }
98
99     /*
100      * Determine record length. Check it against min and max record length.
101      */
102     reclen = (fab->varlength == TRUE) ? isreclen : fab->minreclen;
103     if (reclen < fab->minreclen || reclen > fab->maxreclen) {
104         _setiserrno2(EBADARG, '9', '0');
105         return (ISERROR);
106     }
107
108     /*
109      * Call the Access Method
110      */
111     curpos = _bytearr_dup(&fab->curpos);
112
113     if ((ret = _am_write(fab, record, reclen, &curpos, &recnum)) == ISOK) {
114         isrecnum = recnum;                   /* Set isrecnum */
115     }
116     _bytearr_free(&curpos);
117
118     _seterr_errcode(&fab->errcode);
119
120     return (ret);                            /* Successful write */
121 }
122
123
124 Static int _am_write(Fab *fab, char *record, int reclen,
125                      Bytearray *curpos, Recno *recnum)
126 {
127     return (_amwrite(&fab->isfhandle, record, reclen,
128                      curpos, recnum, &fab->errcode));
129 }