resetting manifest requested domain to floor
[platform/upstream/db4.git] / common / db_byteorder.c
1 /*-
2  * See the file LICENSE for redistribution information.
3  *
4  * Copyright (c) 1996-2009 Oracle.  All rights reserved.
5  *
6  * $Id$
7  */
8
9 #include "db_config.h"
10
11 #include "db_int.h"
12
13 /*
14  * __db_isbigendian --
15  *      Return 1 if big-endian (Motorola and Sparc), not little-endian
16  *      (Intel and Vax).  We do this work at run-time, rather than at
17  *      configuration time so cross-compilation and general embedded
18  *      system support is simpler.
19  *
20  * PUBLIC: int __db_isbigendian __P((void));
21  */
22 int
23 __db_isbigendian()
24 {
25         union {                                 /* From Harbison & Steele.  */
26                 long l;
27                 char c[sizeof(long)];
28         } u;
29
30         u.l = 1;
31         return (u.c[sizeof(long) - 1] == 1);
32 }
33
34 /*
35  * __db_byteorder --
36  *      Return if we need to do byte swapping, checking for illegal
37  *      values.
38  *
39  * PUBLIC: int __db_byteorder __P((ENV *, int));
40  */
41 int
42 __db_byteorder(env, lorder)
43         ENV *env;
44         int lorder;
45 {
46         switch (lorder) {
47         case 0:
48                 break;
49         case 1234:
50                 if (!F_ISSET(env, ENV_LITTLEENDIAN))
51                         return (DB_SWAPBYTES);
52                 break;
53         case 4321:
54                 if (F_ISSET(env, ENV_LITTLEENDIAN))
55                         return (DB_SWAPBYTES);
56                 break;
57         default:
58                 __db_errx(env,
59             "unsupported byte order, only big and little-endian supported");
60                 return (EINVAL);
61         }
62         return (0);
63 }