tt/mini_isam: remove all ancient sccsid blocks
[oweals/cde.git] / cde / lib / tt / mini_isam / iskeyvalid.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: iskeyvalid.c /main/3 1995/10/23 11:42:06 rswiston $                                                          */
28 /*
29  * Copyright (c) 1988 by Sun Microsystems, Inc.
30  */
31
32 /*
33  * iskeydesc.c
34  *
35  * Description:
36  *      Functions dealing with the keydesc structure.
37  *      
38  *
39  */
40
41 #include "isam_impl.h"
42
43 static int _check_typelen();
44
45 /*
46  * _validate_keydesc(keydesc, minreclen)
47  *
48  * Validate key descriptor. minreclen is needed to make suree that all
49  * the key parts have a meaningful offset.
50  *
51  */
52
53 int
54 _validate_keydesc(struct keydesc *keydesc, int minreclen)
55 {
56     int                 nparts;
57     int         i;
58     int                 type, start, length;
59     int                 keylen = 0;
60
61     nparts =  keydesc->k_nparts;
62
63     if (nparts <= 0 || nparts > NPARTS)
64         return (ISERROR);
65
66     for (i = 0; i < nparts;i++) {
67
68         type = keydesc->k_part[i].kp_type & ~ISDESC;
69         start = keydesc->k_part[i].kp_start;
70         length = keydesc->k_part[i].kp_leng;
71
72         if(_check_typelen(type, length) == ISERROR)
73             return (ISERROR);
74
75         if (type < MINTYPE || type >= MAXTYPE)
76             return (ISERROR);
77
78         if (start < 0 || start + length > minreclen)
79             return (ISERROR);
80
81         keylen += length;
82     }
83
84     if(keylen > MAXKEYSIZE)
85         return (ISERROR);
86
87     return (ISOK);
88 }
89
90 /*
91  * _check_typelen()
92  *
93  * Check length against the length of the corresponding type.
94  */
95
96 static int
97 _check_typelen(int type, int length)
98 {
99     switch (type) {
100     case INTTYPE:
101         return ((length == INTSIZE) ? ISOK : ISERROR);
102     case LONGTYPE:
103         return ((length == LONGSIZE) ? ISOK : ISERROR);
104     case FLOATTYPE:
105         return ((length == FLOATSIZE) ? ISOK : ISERROR);
106     case DOUBLETYPE:
107         return ((length == DOUBLESIZE) ? ISOK : ISERROR);
108     case CHARTYPE:
109     case BINTYPE:
110         return ((length > 0) ? ISOK : ISERROR);
111     default:
112         return (ISERROR);
113     }
114 }
115     
116