#include "db_config.h"
#ifndef lint
static const char revid[] = "$Id: db_byteorder.c,v 1.2 2004/03/30 01:21:22 jtownsen Exp $";
#endif
#ifndef NO_SYSTEM_INCLUDES
#include <sys/types.h>
#endif
#include "db_int.h"
int
__db_isbigendian()
{
union {
long l;
char c[sizeof(long)];
} u;
u.l = 1;
return (u.c[sizeof(long) - 1] == 1);
}
int
__db_byteorder(dbenv, lorder)
DB_ENV *dbenv;
int lorder;
{
int is_bigendian;
is_bigendian = __db_isbigendian();
switch (lorder) {
case 0:
break;
case 1234:
if (is_bigendian)
return (DB_SWAPBYTES);
break;
case 4321:
if (!is_bigendian)
return (DB_SWAPBYTES);
break;
default:
__db_err(dbenv,
"unsupported byte order, only big and little-endian supported");
return (EINVAL);
}
return (0);
}