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 librararies 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 static char sccsid[] = "@(#)isdatconv.c 1.5 89/07/17 Copyr 1988 Sun Micro";
32 * Copyright (c) 1988 by Sun Microsystems, Inc.
39 * Conversion function between machine dependent and the X/OPEN
40 * machine independent formats.
42 * Some pieces of code may not be very "structured", but they result in
43 * optimized code with the -O compiler option.
47 #include "isam_impl.h"
51 /* conversion functions for sparc architecture */
53 /* ldlong() - Load a long integer from a potentially unaligned address */
61 register unsigned long val;
63 register unsigned int val;
67 for (i=0; i<LONGSIZE ; i++)
68 val = (val << 8) + *((unsigned char *)p++);
73 /* stlong() - Store a long integer at a potentially unaligned address */
83 for (i=0; i<LONGSIZE ; i++)
84 *--p = (val >> 8*i) & 255;
89 /* ldint() - Load a short integer from a potentially unaligned address */
95 register unsigned int val;
97 val = *((unsigned char *)p++);
98 val = (val << 8) + *((unsigned char *)p++);
104 /* ldunshort - load a unshort integer : for 64K record length */
110 register unsigned int val;
112 val = *((unsigned char *)p++);
113 val = (val << 8) + *((unsigned char *)p++);
115 return ((u_short)val);
118 /* stint() - Store a short integer at a potentially unaligned address */
127 *--p = (val >> 8) & 255;
132 /* ldchar() - Load character field */
135 ldchar(src, len, dst)
145 /* Load the entire string. */
146 memcpy((void *) dst, (const void *) src, len);
148 /* Remove trailing blanks. */
160 stchar(src, dst, len)
170 /* Copy up to NULL character. */
172 if ((c = *src++) == '\0')
177 /* Pad with blanks. */
179 (void) memset((void *) dst, BLANK, len);
182 /* ldchar2() - Load character field (C style, NULL padded) */
185 ldchar2(src, len, dst)
195 /* Load the entire string. */
196 memcpy((void *) dst, (const void *) src, len);
201 stchar2(src, dst, len)
211 /* Copy up to a NULL character. */
213 if ((c = *src++) == '\0')
218 /* Pad with NULLs. */
223 /* ldfloat() - Load a float number from a potentially unaligned address */
233 register unsigned int val;
235 val = *((unsigned char *)p++);
236 val = (val << 8) + *((unsigned char *)p++);
237 val = (val << 8) + *((unsigned char *)p++);
238 val = (val << 8) + *((unsigned char *)p++);
244 /* stfloat() - Store a float number at a potentially unaligned address */
248 float f; /* Bug - it is passed as double */
251 register unsigned val;
257 uval.fval = f; /* This fixes compiler bug */
262 *--p = (val >> 8) & 255;
263 *--p = (val >> 16) & 255;
264 *--p = (val >> 24) & 255;
269 #if sparc | mc68000 /* MRJ */
271 /* ldbld() - Load a double float number from a potentially unaligned address */
279 memcpy((void *)&val, (const void *) p, DOUBLESIZE);
283 /* stdbl() - Store a double float number at a potentially unaligned address */
290 memcpy ( p,(char *)&val, DOUBLESIZE);
293 #else /* 386i -- do it the long way round.... */
295 /* ldbld() - Load a double float number from a potentially unaligned address */
303 char sval[DOUBLESIZE];
312 for (i=0; i<DOUBLESIZE; i++)
317 /* stdbl() - Store a double float number at a potentially unaligned address */
326 char sval[DOUBLESIZE];
336 for (i=0; i<DOUBLESIZE; i++)