00001 /*- 00002 * See the file LICENSE for redistribution information. 00003 * 00004 * Copyright (c) 1996, 1997, 1998, 1999, 2000 00005 * Sleepycat Software. All rights reserved. 00006 */ 00007 00008 #include "config.h" 00009 00010 #ifndef lint 00011 static const char revid[] = "$Id: db__byteorder_8c-source.html,v 1.1 2008年06月08日 10:17:21 sebdiaz Exp $"; 00012 #endif /* not lint */ 00013 00014 #ifndef NO_SYSTEM_INCLUDES 00015 #include <sys/types.h> 00016 00017 #ifdef HAVE_ENDIAN_H 00018 #include <endian.h> 00019 #if BYTE_ORDER == BIG_ENDIAN 00020 #define WORDS_BIGENDIAN 1 00021 #endif 00022 #endif 00023 00024 #include <errno.h> 00025 #endif 00026 00027 #include "db_int.h" 00028 #include "common_ext.h" 00029 00030 /* 00031 * CDB___db_byteorder -- 00032 * Return if we need to do byte swapping, checking for illegal 00033 * values. 00034 * 00035 * PUBLIC: int CDB___db_byteorder __P((DB_ENV *, int)); 00036 */ 00037 int 00038 CDB___db_byteorder(dbenv, lorder) 00039 DB_ENV *dbenv; 00040 int lorder; 00041 { 00042 switch (lorder) { 00043 case 0: 00044 break; 00045 case 1234: 00046 #if defined(WORDS_BIGENDIAN) 00047 return (DB_SWAPBYTES); 00048 #else 00049 break; 00050 #endif 00051 case 4321: 00052 #if defined(WORDS_BIGENDIAN) 00053 break; 00054 #else 00055 return (DB_SWAPBYTES); 00056 #endif 00057 default: 00058 CDB___db_err(dbenv, 00059 "unsupported byte order, only big and little-endian supported"); 00060 return (EINVAL); 00061 } 00062 return (0); 00063 }