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