8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / lib / libtnf / datum.c
blob0193f23f903aa1ee1ba72dd84b6d20830f492f2a
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
7 * with the License.
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
20 * CDDL HEADER END
23 * Copyright (c) 1994, by Sun Microsytems, Inc.
26 #pragma ident "%Z%%M% %I% %E% SMI"
28 #include "libtnf.h"
31 * Defines
34 #define DATUM_KIND(d) (DATUM_INFO(d)->kind)
37 * Declarations
40 static int has_prop(tnf_datum_t, tag_props_t);
43 * Datum operations: for more debuggability
46 #ifndef _DATUM_MACROS
48 tnf_datum_t
49 _tnf_datum(struct taginfo *info, caddr_t val)
51 return (_DATUM(info, val));
54 struct taginfo *
55 _tnf_datum_info(tnf_datum_t datum)
57 return ((struct taginfo *)_DATUM_HI(datum));
60 caddr_t
61 _tnf_datum_val(tnf_datum_t datum)
63 return ((caddr_t)_DATUM_LO(datum));
66 #endif
69 * Check for valid datum
72 void
73 _tnf_check_datum(tnf_datum_t datum)
75 caddr_t val;
76 TNF *tnf;
78 if (datum == TNF_DATUM_NULL)
79 _tnf_error(NULL, TNF_ERR_BADTNF);
81 val = DATUM_VAL(datum);
82 tnf = DATUM_TNF(datum);
84 if ((val <= tnf->file_start) || (val >= tnf->file_end))
85 _tnf_error(tnf, TNF_ERR_BADDATUM);
89 * Retrieve datum kind from cached information
92 tnf_kind_t
93 tnf_get_kind(tnf_datum_t datum)
95 CHECK_DATUM(datum);
96 /* The kind field is always completely initialized */
97 return (DATUM_KIND(datum));
101 * Classification predicates: check the cached tag props
104 static int
105 has_prop(tnf_datum_t datum, tag_props_t prop)
107 CHECK_DATUM(datum);
109 /* Note: No need to get base info because props inherited */
110 return (INFO_PROP(DATUM_INFO(datum), prop));
114 tnf_is_inline(tnf_datum_t datum)
116 return (has_prop(datum, TAG_PROP_INLINE));
120 tnf_is_scalar(tnf_datum_t datum)
122 return (has_prop(datum, TAG_PROP_SCALAR));
126 tnf_is_record(tnf_datum_t datum) /* XXX was: tnf_is_tagged */
128 return (has_prop(datum, TAG_PROP_TAGGED));
132 tnf_is_array(tnf_datum_t datum)
134 return (has_prop(datum, TAG_PROP_ARRAY));
138 tnf_is_string(tnf_datum_t datum)
140 return (has_prop(datum, TAG_PROP_STRING));
144 tnf_is_struct(tnf_datum_t datum)
146 return (has_prop(datum, TAG_PROP_STRUCT));
150 tnf_is_type(tnf_datum_t datum)
152 return (has_prop(datum, TAG_PROP_TYPE));
156 * Get the type datum for any datum
159 tnf_datum_t
160 tnf_get_type(tnf_datum_t datum)
162 struct taginfo *info;
164 CHECK_DATUM(datum);
166 info = DATUM_INFO(datum);
167 return (DATUM(info->meta, (caddr_t)info->tag));
171 * Get the type name for any datum
172 * XXX Beware: this is a pointer into the file
175 char *
176 tnf_get_type_name(tnf_datum_t datum)
178 CHECK_DATUM(datum);
179 return (DATUM_INFO(datum)->name); /* cached */
183 * Get the size of any datum
186 size_t
187 tnf_get_size(tnf_datum_t datum)
189 struct taginfo *info;
190 size_t size;
192 CHECK_DATUM(datum);
194 info = DATUM_INFO(datum);
195 size = info->size;
197 if (size == (size_t)-1) /* self sized */
198 /* XXX tnf_get_slot_named(datum, TNF_N_SELF_SIZE) */
199 /* LINTED pointer cast may result in improper alignment */
200 return (_tnf_get_self_size(info->tnf, DATUM_RECORD(datum)));
201 else
202 return (size);
206 * Get raw pointer to any datum
209 caddr_t
210 tnf_get_raw(tnf_datum_t datum)
212 CHECK_DATUM(datum);
213 return (DATUM_VAL(datum));