Add GNU LGPL headers to all .c .C and .h files
[oweals/cde.git] / cde / lib / tt / mini_isam / isaddprimary.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: isaddprimary.c /main/3 1995/10/23 11:33:35 rswiston $                                                        */
28 #ifndef lint
29 static char sccsid[] = "@(#)isaddprimary.c 1.8 89/07/17 Copyr 1988 Sun Micro";
30 #endif
31 /* @(#)isaddprimary.c   1.7 93/09/07
32  * Copyright (c) 1988 by Sun Microsystems, Inc.
33  */
34
35 /*
36  * isaddprimary.c
37  *
38  * Description:
39  *      Add secondary index to ISAM file
40  */
41
42
43 #include "isam_impl.h"
44 #include <sys/time.h>
45
46 Static int _am_addprimary();
47
48
49 /*
50  * err = isaddprimary(isfd, keydesc)
51  *
52  * Isaddprimary() is used to add primary index to ISAM file. 
53  *
54  * This call is not part of the X/OPEN sprec.
55  *
56  * Errors:
57  *      EBADKEY error in keydesc        
58  *      EDUPL   there are duplicate keys and the keydesc does not allow
59  *              duplicate keys
60  *      EKEXISTS key with the same key descriptor already exists
61  *      EKEXISTS the ISAM file already has a primary index.
62  *      ENOTEXCL ISAM file is not open in exclusive mode
63  *      ENOTOPEN the ISAM file is not open in ISINOUT mode.
64  *      EACCES  Cannot create index file because of UNIX error.
65  */
66
67 int 
68 isaddprimary(isfd, keydesc)
69     int                 isfd;
70     struct keydesc      *keydesc;
71 {
72     register Fab        *fab;
73     int                 ret;
74
75     /*
76      * Get File Access Block.
77      */
78     if ((fab = _isfd_find(isfd)) == NULL) {
79         _setiserrno2(ENOTOPEN, '9', '0');
80         return (ISERROR);
81     }
82
83     /*
84      * Check that the open mode was ISOUTPUT
85      */
86     if (fab->openmode != OM_INOUT) {
87         _setiserrno2(ENOTOPEN, '9', '0');
88         return (ISERROR);
89     }
90
91     ret = _am_addprimary(fab, keydesc);
92     _seterr_errcode(&fab->errcode);
93
94     return (ret);                            /* Successful write */
95 }
96
97 Static int _am_addprimary(fab, keydesc)
98     register Fab        *fab;
99     struct keydesc      *keydesc;
100 {
101     return (_amaddprimary(&fab->isfhandle, keydesc, &fab->errcode));
102 }