c1ae9e509457fe297860510dc021a2ce823c951a
[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 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: 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(int isfd, struct keydesc *keydesc)
69 {
70     Fab *fab;
71     int                 ret;
72
73     /*
74      * Get File Access Block.
75      */
76     if ((fab = _isfd_find(isfd)) == NULL) {
77         _setiserrno2(ENOTOPEN, '9', '0');
78         return (ISERROR);
79     }
80
81     /*
82      * Check that the open mode was ISOUTPUT
83      */
84     if (fab->openmode != OM_INOUT) {
85         _setiserrno2(ENOTOPEN, '9', '0');
86         return (ISERROR);
87     }
88
89     ret = _am_addprimary(fab, keydesc);
90     _seterr_errcode(&fab->errcode);
91
92     return (ret);                            /* Successful write */
93 }
94
95 Static int _am_addprimary(Fab *fab, struct keydesc *keydesc)
96 {
97     return (_amaddprimary(&fab->isfhandle, keydesc, &fab->errcode));
98 }