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
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]
23 * Copyright (c) 1994, by Sun Microsytems, Inc.
26 #pragma ident "%Z%%M% %I% %E% SMI"
34 #define CHECK_SCALAR(datum) check_scalar(datum)
36 #define DATUM_NATIVE(x) DATUM_TNF(datum)->file_native
42 static void check_scalar(tnf_datum_t
);
44 static tnf_uint64_t
get_uint64(TNF
*tnf
, caddr_t val
);
51 check_scalar(tnf_datum_t datum
)
54 if (!INFO_SCALAR(DATUM_INFO(datum
)))
55 _tnf_error(DATUM_TNF(datum
), TNF_ERR_TYPEMISMATCH
);
56 /* XXX Need to check for exact scalar type match as well */
60 * Exported scalar operations
63 /* No swapping required: */
66 tnf_get_char(tnf_datum_t datum
)
69 return (*(char *)DATUM_VAL(datum
));
73 tnf_get_int8(tnf_datum_t datum
)
76 return (*(tnf_int8_t
*)DATUM_VAL(datum
));
80 tnf_get_int16(tnf_datum_t datum
)
85 /* LINTED pointer cast may result in improper alignment */
86 val
= *(tnf_int16_t
*)DATUM_VAL(datum
);
87 return (DATUM_NATIVE(datum
) ? val
: _tnf_swap16(val
));
90 /* 32-bit integers: */
93 tnf_get_int32(tnf_datum_t datum
)
96 /* LINTED pointer cast may result in improper alignment */
97 return (_GET_INT32(DATUM_TNF(datum
), DATUM_VAL(datum
)));
100 /* 64-bit integers: */
103 get_uint64(TNF
*tnf
, caddr_t val
)
105 tnf_uint32_t hi32
, lo32
; /* XXX both assumed unsigned */
107 /* XXX Can't rely on address alignment */
108 /* LINTED pointer cast may result in improper alignment */
109 hi32
= *(tnf_uint32_t
*)val
;
110 /* LINTED pointer cast may result in improper alignment */
111 lo32
= *(tnf_uint32_t
*)(val
+ sizeof (tnf_uint32_t
));
113 #ifdef _LONG_LONG_HTOL
115 if (tnf
->file_native
)
116 return ((((tnf_uint64_t
)hi32
) << 32)
117 + (tnf_uint64_t
)lo32
);
119 /* XXX Assume words are swapped as well: */
120 return ((((tnf_uint64_t
)_tnf_swap32(lo32
)) << 32)
121 + (tnf_uint64_t
)_tnf_swap32(hi32
));
124 if (tnf
->file_native
)
125 return ((((tnf_uint64_t
)lo32
) << 32)
126 + (tnf_uint64_t
)hi32
);
128 /* XXX Assume words are swapped as well: */
129 return ((((tnf_uint64_t
)_tnf_swap32(hi32
)) << 32)
130 + (tnf_uint64_t
)_tnf_swap32(lo32
));
135 tnf_get_int64(tnf_datum_t datum
)
138 return (get_uint64(DATUM_TNF(datum
), DATUM_VAL(datum
)));
144 tnf_get_float32(tnf_datum_t datum
)
153 /* LINTED pointer cast may result in improper alignment */
154 u
.i32
= _GET_UINT32(DATUM_TNF(datum
), DATUM_VAL(datum
)); /* XXX */
159 tnf_get_float64(tnf_datum_t datum
)
168 u
.i64
= get_uint64(DATUM_TNF(datum
), DATUM_VAL(datum
)); /* XXX */