1*7c478bd9Sstevel@tonic-gate /*-
2*7c478bd9Sstevel@tonic-gate  * See the file LICENSE for redistribution information.
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * Copyright (c) 1996, 1997
5*7c478bd9Sstevel@tonic-gate  *	Sleepycat Software.  All rights reserved.
6*7c478bd9Sstevel@tonic-gate  */
7*7c478bd9Sstevel@tonic-gate /*
8*7c478bd9Sstevel@tonic-gate  * Copyright (c) 1998 by Sun Microsystems, Inc.
9*7c478bd9Sstevel@tonic-gate  * All rights reserved.
10*7c478bd9Sstevel@tonic-gate  */
11*7c478bd9Sstevel@tonic-gate 
12*7c478bd9Sstevel@tonic-gate #include "config.h"
13*7c478bd9Sstevel@tonic-gate 
14*7c478bd9Sstevel@tonic-gate #ifndef lint
15*7c478bd9Sstevel@tonic-gate static const char sccsid[] = "@(#)db_byteorder.c	10.4 (Sleepycat) 9/4/97";
16*7c478bd9Sstevel@tonic-gate static const char sccsi2[] = "%W% (Sun) %G%";
17*7c478bd9Sstevel@tonic-gate #endif /* not lint */
18*7c478bd9Sstevel@tonic-gate 
19*7c478bd9Sstevel@tonic-gate #ifndef NO_SYSTEM_INCLUDES
20*7c478bd9Sstevel@tonic-gate #include <sys/types.h>
21*7c478bd9Sstevel@tonic-gate 
22*7c478bd9Sstevel@tonic-gate #ifdef HAVE_ENDIAN_H
23*7c478bd9Sstevel@tonic-gate #include <endian.h>
24*7c478bd9Sstevel@tonic-gate #if BYTE_ORDER == BIG_ENDIAN
25*7c478bd9Sstevel@tonic-gate #define	WORDS_BIGENDIAN	1
26*7c478bd9Sstevel@tonic-gate #endif
27*7c478bd9Sstevel@tonic-gate #endif
28*7c478bd9Sstevel@tonic-gate 
29*7c478bd9Sstevel@tonic-gate #include <errno.h>
30*7c478bd9Sstevel@tonic-gate #endif
31*7c478bd9Sstevel@tonic-gate 
32*7c478bd9Sstevel@tonic-gate #include "db_int.h"
33*7c478bd9Sstevel@tonic-gate #include "common_ext.h"
34*7c478bd9Sstevel@tonic-gate 
35*7c478bd9Sstevel@tonic-gate /*
36*7c478bd9Sstevel@tonic-gate  * __db_byteorder --
37*7c478bd9Sstevel@tonic-gate  *	Return if we need to do byte swapping, checking for illegal
38*7c478bd9Sstevel@tonic-gate  *	values.
39*7c478bd9Sstevel@tonic-gate  *
40*7c478bd9Sstevel@tonic-gate  * PUBLIC: int __db_byteorder __P((DB_ENV *, int));
41*7c478bd9Sstevel@tonic-gate  */
42*7c478bd9Sstevel@tonic-gate int
__db_byteorder(dbenv,lorder)43*7c478bd9Sstevel@tonic-gate __db_byteorder(dbenv, lorder)
44*7c478bd9Sstevel@tonic-gate 	DB_ENV *dbenv;
45*7c478bd9Sstevel@tonic-gate 	int lorder;
46*7c478bd9Sstevel@tonic-gate {
47*7c478bd9Sstevel@tonic-gate 	switch (lorder) {
48*7c478bd9Sstevel@tonic-gate 	case 0:
49*7c478bd9Sstevel@tonic-gate 		break;
50*7c478bd9Sstevel@tonic-gate 	case 1234:
51*7c478bd9Sstevel@tonic-gate #if defined(WORDS_BIGENDIAN)
52*7c478bd9Sstevel@tonic-gate 		return (DB_SWAPBYTES);
53*7c478bd9Sstevel@tonic-gate #else
54*7c478bd9Sstevel@tonic-gate 		break;
55*7c478bd9Sstevel@tonic-gate #endif
56*7c478bd9Sstevel@tonic-gate 	case 4321:
57*7c478bd9Sstevel@tonic-gate #if defined(WORDS_BIGENDIAN)
58*7c478bd9Sstevel@tonic-gate 		break;
59*7c478bd9Sstevel@tonic-gate #else
60*7c478bd9Sstevel@tonic-gate 		return (DB_SWAPBYTES);
61*7c478bd9Sstevel@tonic-gate #endif
62*7c478bd9Sstevel@tonic-gate 	default:
63*7c478bd9Sstevel@tonic-gate 		__db_err(dbenv,
64*7c478bd9Sstevel@tonic-gate 		    "illegal byte order, only big and little-endian supported");
65*7c478bd9Sstevel@tonic-gate 		return (EINVAL);
66*7c478bd9Sstevel@tonic-gate 	}
67*7c478bd9Sstevel@tonic-gate 	return (0);
68*7c478bd9Sstevel@tonic-gate }
69