2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
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)
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
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
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: isdatconv.c /main/3 1995/10/23 11:37:16 rswiston $ */
29 * Copyright (c) 1988 by Sun Microsystems, Inc.
36 * Conversion function between machine dependent and the X/OPEN
37 * machine independent formats.
39 * Some pieces of code may not be very "structured", but they result in
40 * optimized code with the -O compiler option.
44 #include "isam_impl.h"
48 /* conversion functions for sparc architecture */
50 /* ldlong() - Load a long integer from a potentially unaligned address */
63 for (i=0; i<LONGSIZE ; i++)
64 val = (val << 8) + *((unsigned char *)p++);
69 /* stlong() - Store a long integer at a potentially unaligned address */
72 stlong(long val, char *p)
77 for (i=0; i<LONGSIZE ; i++)
78 *--p = (val >> 8*i) & 255;
83 /* ldint() - Load a short integer from a potentially unaligned address */
90 val = *((unsigned char *)p++);
91 val = (val << 8) + *((unsigned char *)p++);
97 /* ldunshort - load a unshort integer : for 64K record length */
104 val = *((unsigned char *)p++);
105 val = (val << 8) + *((unsigned char *)p++);
107 return ((u_short)val);
110 /* stint() - Store a short integer at a potentially unaligned address */
113 stint(short val, char *p)
117 *--p = (val >> 8) & 255;
122 /* ldchar() - Load character field */
125 ldchar(char *src, int len, char *dst)
132 /* Load the entire string. */
133 memcpy((void *) dst, (const void *) src, len);
135 /* Remove trailing blanks. */
148 stchar(char *src, char *dst, int len)
155 /* Copy up to NULL character. */
157 if ((c = *src++) == '\0')
162 /* Pad with blanks. */
164 (void) memset((void *) dst, BLANK, len);
168 /* ldchar2() - Load character field (C style, NULL padded) */
171 ldchar2(char *src, int len, char *dst)
177 /* Load the entire string. */
178 memcpy((void *) dst, (const void *) src, len);
184 stchar2(char *src, char *dst, int len)
191 /* Copy up to a NULL character. */
193 if ((c = *src++) == '\0')
198 /* Pad with NULLs. */
204 /* ldfloat() - Load a float number from a potentially unaligned address */
215 val = *((unsigned char *)p++);
216 val = (val << 8) + *((unsigned char *)p++);
217 val = (val << 8) + *((unsigned char *)p++);
218 val = (val << 8) + *((unsigned char *)p++);
224 /* stfloat() - Store a float number at a potentially unaligned address */
226 /* f, Bug - it is passed as double */
228 stfloat(float f, char *p)
236 uval.fval = f; /* This fixes compiler bug */
241 *--p = (val >> 8) & 255;
242 *--p = (val >> 16) & 255;
243 *--p = (val >> 24) & 255;
248 #if sparc | mc68000 /* MRJ */
250 /* ldbld() - Load a double float number from a potentially unaligned address */
257 memcpy((void *)&val, (const void *) p, DOUBLESIZE);
261 /* stdbl() - Store a double float number at a potentially unaligned address */
264 stdbl(double val, char *p)
266 memcpy ( p,(char *)&val, DOUBLESIZE);
270 #else /* 386i -- do it the long way round.... */
272 /* ldbld() - Load a double float number from a potentially unaligned address */
279 char sval[DOUBLESIZE];
288 for (i=0; i<DOUBLESIZE; i++)
293 /* stdbl() - Store a double float number at a potentially unaligned address */
296 stdbl(double val, char *p)
300 char sval[DOUBLESIZE];
310 for (i=0; i<DOUBLESIZE; i++)