Update.
[glibc.git] / db2 / common / db_byteorder.c
blobcadf7428516e6c94f39d93b7de600440d0853b89
1 /*-
2 * See the file LICENSE for redistribution information.
4 * Copyright (c) 1996, 1997, 1998
5 * Sleepycat Software. All rights reserved.
6 */
8 #include "config.h"
10 #ifndef lint
11 static const char sccsid[] = "@(#)db_byteorder.c 10.5 (Sleepycat) 4/10/98";
12 #endif /* not lint */
14 #ifndef NO_SYSTEM_INCLUDES
15 #include <sys/types.h>
17 #ifdef HAVE_ENDIAN_H
18 #include <endian.h>
19 #if BYTE_ORDER == BIG_ENDIAN
20 #define WORDS_BIGENDIAN 1
21 #endif
22 #endif
24 #include <errno.h>
25 #endif
27 #include "db_int.h"
28 #include "common_ext.h"
31 * __db_byteorder --
32 * Return if we need to do byte swapping, checking for illegal
33 * values.
35 * PUBLIC: int __db_byteorder __P((DB_ENV *, int));
37 int
38 __db_byteorder(dbenv, lorder)
39 DB_ENV *dbenv;
40 int lorder;
42 switch (lorder) {
43 case 0:
44 break;
45 case 1234:
46 #if defined(WORDS_BIGENDIAN)
47 return (DB_SWAPBYTES);
48 #else
49 break;
50 #endif
51 case 4321:
52 #if defined(WORDS_BIGENDIAN)
53 break;
54 #else
55 return (DB_SWAPBYTES);
56 #endif
57 default:
58 __db_err(dbenv,
59 "illegal byte order, only big and little-endian supported");
60 return (EINVAL);
62 return (0);