even though oracle still checks b.order at runtime, the rest of
obsd db 1.85 functions, namely those pertaining to hash(3), use
BYTE_ORDER

so,

1. it's inconsistent to do runtime on btree but not on hash

2. complicating the code by checking endianness after assigning
defaults -- even though all other user supplied input checks happen
*before* falling back to defaults -- just in case that the machine
might be "3412", is pretty silly, specially at runtime where a
constant abort on pdp-endian hosts should be anticipated by a failed
compiletime check. (i'm gonna keep saying the wrong answer until
it's right!)

3. oracle's cross compilation concerns really aren't applicable,
and if they were, they would also have to include hash

Index: src/lib/libc/db/btree/bt_open.c
===================================================================
RCS file: /cvs/src/lib/libc/db/btree/bt_open.c,v
retrieving revision 1.14
diff -u -p -r1.14 bt_open.c
--- src/lib/libc/db/btree/bt_open.c     17 Sep 2007 07:07:23 -0000      1.14
+++ src/lib/libc/db/btree/bt_open.c     27 Nov 2011 07:02:05 -0000
@@ -60,7 +60,6 @@
 #define        MINPSIZE        128
 #endif
 
-static int byteorder(void);
 static int nroot(BTREE *);
 static int tmp(void);
 
@@ -91,7 +90,7 @@ __bt_open(const char *fname, int flags, 
        DB *dbp;
        pgno_t ncache;
        ssize_t nr;
-       int machine_lorder, saved_errno;
+       int saved_errno;
 
        t = NULL;
 
@@ -102,7 +101,6 @@ __bt_open(const char *fname, int flags, 
         * file is opened.  Also, the file's page size can cause the cachesize
         * to change.
         */
-       machine_lorder = byteorder();
        if (openinfo) {
                b = *openinfo;
 
@@ -134,22 +132,25 @@ __bt_open(const char *fname, int flags, 
                                b.prefix = __bt_defpfx;
                }
 
-               if (b.lorder == 0)
-                       b.lorder = machine_lorder;
+               switch(b.lorder) {
+               case 0:
+                       b.lorder = BYTE_ORDER;
+               case BIG_ENDIAN:
+               case LITTLE_ENDIAN:
+                       break;
+               default:
+                       goto einval;
+               }
        } else {
                b.compare = __bt_defcmp;
                b.cachesize = 0;
                b.flags = 0;
-               b.lorder = machine_lorder;
+               b.lorder = BYTE_ORDER;
                b.minkeypage = DEFMINKEYPAGE;
                b.prefix = __bt_defpfx;
                b.psize = 0;
        }
 
-       /* Check for the ubiquitous PDP-11. */
-       if (b.lorder != BIG_ENDIAN && b.lorder != LITTLE_ENDIAN)
-               goto einval;
-
        /* Allocate and initialize DB and BTREE structures. */
        if ((t = (BTREE *)malloc(sizeof(BTREE))) == NULL)
                goto err;
@@ -164,7 +165,7 @@ __bt_open(const char *fname, int flags, 
        if ((t->bt_dbp = dbp = (DB *)malloc(sizeof(DB))) == NULL)
                goto err;
        memset(t->bt_dbp, 0, sizeof(DB));
-       if (t->bt_lorder != machine_lorder)
+       if (t->bt_lorder != BYTE_ORDER)
                F_SET(t, B_NEEDSWAP);
 
        dbp->type = DB_BTREE;
@@ -406,24 +407,6 @@ tmp(void)
                (void)unlink(path);
        (void)sigprocmask(SIG_SETMASK, &oset, NULL);
        return(fd);
-}
-
-static int
-byteorder(void)
-{
-       u_int32_t x;
-       u_char *p;
-
-       x = 0x01020304;
-       p = (u_char *)&x;
-       switch (*p) {
-       case 1:
-               return (BIG_ENDIAN);
-       case 4:
-               return (LITTLE_ENDIAN);
-       default:
-               return (0);
-       }
 }
 
 int

Reply via email to