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#pragma ident	"%Z%%M%	%I%	%E% SMI"
15
16#ifndef lint
17static const char sccsid[] = "@(#)db_byteorder.c	10.4 (Sleepycat) 9/4/97";
18static const char sccsi2[] = "%W% (Sun) %G%";
19#endif /* not lint */
20
21#ifndef NO_SYSTEM_INCLUDES
22#include <sys/types.h>
23
24#ifdef HAVE_ENDIAN_H
25#include <endian.h>
26#if BYTE_ORDER == BIG_ENDIAN
27#define	WORDS_BIGENDIAN	1
28#endif
29#endif
30
31#include <errno.h>
32#endif
33
34#include "db_int.h"
35#include "common_ext.h"
36
37/*
38 * __db_byteorder --
39 *	Return if we need to do byte swapping, checking for illegal
40 *	values.
41 *
42 * PUBLIC: int __db_byteorder __P((DB_ENV *, int));
43 */
44int
45__db_byteorder(dbenv, lorder)
46	DB_ENV *dbenv;
47	int lorder;
48{
49	switch (lorder) {
50	case 0:
51		break;
52	case 1234:
53#if defined(WORDS_BIGENDIAN)
54		return (DB_SWAPBYTES);
55#else
56		break;
57#endif
58	case 4321:
59#if defined(WORDS_BIGENDIAN)
60		break;
61#else
62		return (DB_SWAPBYTES);
63#endif
64	default:
65		__db_err(dbenv,
66		    "illegal byte order, only big and little-endian supported");
67		return (EINVAL);
68	}
69	return (0);
70}
71