-/* $Id: mandocdb.c,v 1.18 2011/12/01 21:05:49 kristaps Exp $ */
+/* $Id: mandocdb.c,v 1.23 2011/12/03 18:47:09 kristaps Exp $ */
/*
* Copyright (c) 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2011 Ingo Schwarze <schwarze@openbsd.org>
#include <string.h>
#include <unistd.h>
-#ifdef __linux__
+#if defined(__linux__)
+# include <endian.h>
# include <db_185.h>
+#elif defined(__APPLE__)
+# include <libkern/OSByteOrder.h>
+# include <db.h>
#else
# include <db.h>
#endif
* into the database.
*/
- vbuf.rec = rec;
+ vbuf.rec = htobe32(rec);
seq = R_FIRST;
while (0 == (ch = (*hash->seq)(hash, &key, &val, seq))) {
seq = R_NEXT;
-
- vbuf.mask = *(uint64_t *)val.data;
+ vbuf.mask = htobe64(*(uint64_t *)val.data);
val.size = sizeof(struct db_val);
val.data = &vbuf;
-
dbt_put(db, dbf, &key, &val);
}
if (ch < 0) {
break;
vbuf = val.data;
- if (*maxrec != vbuf->rec)
+ if (*maxrec != betoh32(vbuf->rec))
continue;
if ((ch = (*db->del)(db, &key, R_CURSOR)) < 0)