tt/mini_isam: remove all ancient sccsid blocks
[oweals/cde.git] / cde / lib / tt / mini_isam / isindexinfo.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: isindexinfo.c /main/3 1995/10/23 11:40:56 rswiston $                                                         */
28 /*
29  * Copyright (c) 1988 by Sun Microsystems, Inc.
30  */
31
32 /*
33  * isindexinfo.c
34  *
35  * Description:
36  *      Access file status information
37  */
38
39
40 #include "isam_impl.h"
41 #include <sys/time.h>
42
43 #define ZERO 0
44
45 /*
46  * err = isindexinfo(isfd, buffer, number)
47  *
48  * Return information about index.
49  * Return information about the data file (if number == 0).
50  *
51  * (this function is overloaded).
52  *
53  * Errors:
54  *      EBADARG number is out of range
55  *      ENOTOPEN isfd is not ISAM file descriptor of open ISAM file
56  */
57
58 #define dibuf ((struct dictinfo *)buffer)
59
60 int
61 isindexinfo(int isfd, struct keydesc *buffer, int number)
62 {
63     Fab *fab;
64     int                 ret;
65     Fcb                 *fcb = NULL;
66
67     /*
68      * Get File Access Block.
69      */
70     if ((fab = _isfd_find(isfd)) == NULL) {
71         _setiserrno2(ENOTOPEN, '9', '0');
72         return (ISERROR);
73     }
74
75     /*
76      * Call the Access Method or RPC client function, depending whether
77      * the file is local or remote.
78      */
79
80     _isam_entryhook();
81
82     /*
83      * Get FCB corresponding to the isfhandle handle.
84      */
85     if ((fcb = _openfcb(&fab->isfhandle, &fab->errcode)) == NULL) {
86         _isam_exithook();
87         return (ISERROR);
88     }
89
90     /*
91      * Update information in FCB from CNTL page on the disk
92      */
93     (void)_isfcb_cntlpg_r(fcb);
94
95     /*
96      * Validate number argument.
97      */
98     if (number < 0 || number > fcb->nkeys) {
99         _amseterrcode(&fab->errcode, EBADARG);
100         goto ERROR;
101     }
102
103     if (number == 0) {
104         
105         /*
106          * Return dictinfo structure.
107          */
108         dibuf->di_nkeys = fcb->nkeys;
109         dibuf->di_recsize = fcb->maxreclen;
110         dibuf->di_idxsize = fcb->keys[0].k2_len;
111         dibuf->di_nrecords = fcb->nrecords;
112
113         /* Set msb of di_nkeys for variable length records. */
114         if (fcb->varflag == TRUE) 
115             dibuf->di_nkeys |= DICTVARLENBIT;
116     }
117     else {
118
119         /*
120          * Return index information.
121          */
122         _iskey_itox(fcb->keys + number - 1, buffer);
123     }
124
125     _amseterrcode(&fab->errcode, ISOK);
126
127 /* XXX This fixes a core dump that occurs when isindexinfo is
128 *      called on brand new tables
129     _isdisk_commit();
130     _isdisk_sync();
131     _isdisk_inval();
132 */
133
134     _isam_exithook();
135     ret = ISOK;
136     goto CLEANUP;
137
138  ERROR:
139     /*
140      * Restore FCB from CNTL page.
141      */
142
143     _isdisk_rollback();
144     _isdisk_inval();
145
146     _isam_exithook();
147     ret = ISERROR;
148
149  CLEANUP: 
150
151     if (ret == ISOK)
152         isreclen = fab->minreclen;           /* for variable length */
153
154     _seterr_errcode(&fab->errcode);
155
156     /*
157      * This is a patch to conform with the VSX 3.0 test that checks
158      * that k_leng == 2 and k_type == 1 for index 1 if the ISAM file
159      * has no primary key. I suspect that these numbers are returned by
160      * C-ISAM and the author of VSX tests diligently checks them even 
161      * though they have no meaning.
162      */
163     if (ret == ISOK && number == 1 && buffer->k_nparts == 0) {
164         buffer->k_leng = 2;
165         buffer->k_type = INTTYPE;
166     }
167     
168     return (ret);               
169 }
170