From d1b540afdd77328cb66da01be9399236630bf4f6 Mon Sep 17 00:00:00 2001 From: Kristaps Dzonsons Date: Fri, 2 Dec 2011 00:21:56 +0000 Subject: This is a little gross: Linux and Apple need lots some cajoling to work with byte-swapping. Tested on Mac. Any Linux machines somebody can test on? Anybody? While here, note the correct byte-size in mandocdb(8) and also note field widths and endianness. The btree is now endian-neutral. --- apropos_db.c | 10 +++++++++- config.h.post | 10 ++++++++++ mandocdb.8 | 8 ++++---- mandocdb.c | 6 +++++- 4 files changed, 28 insertions(+), 6 deletions(-) diff --git a/apropos_db.c b/apropos_db.c index 6621a1a1..6859a914 100644 --- a/apropos_db.c +++ b/apropos_db.c @@ -15,6 +15,10 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + #include #include #include @@ -24,8 +28,12 @@ #include #include -#ifdef __linux__ +#if defined(__linux__) +# include # include +#elif defined(__APPLE__) +# include +# include #else # include #endif diff --git a/config.h.post b/config.h.post index 3cdf9a78..62ce4ea6 100644 --- a/config.h.post +++ b/config.h.post @@ -15,6 +15,16 @@ # endif #endif +#if defined(__APPLE__) +# define htobe32(x) OSSwapHostToBigInt32(x) +# define betoh32(x) OSSwapBigToHostInt32(x) +# define htobe64(x) OSSwapHostToBigInt64(x) +# define betoh64(x) OSSwapBigToHostInt64(x) +#elif defined(__linux__) +# define betoh32(x) be32toh(x) +# define betoh64(x) be64toh(x) +#endif + #ifndef HAVE_STRLCAT extern size_t strlcat(char *, const char *, size_t); #endif diff --git a/mandocdb.8 b/mandocdb.8 index cba2c011..bdc81893 100644 --- a/mandocdb.8 +++ b/mandocdb.8 @@ -137,11 +137,11 @@ The keyword database, is a .Xr btree 3 database of NUL-terminated keywords (record length is non-zero string -length plus one) mapping to a 8-byte binary field consisting of the -keyword type and source +length plus one) mapping to a 12-byte binary field consisting of the +64-bit keyword type and 32-bit source .Sx Index Database -record number. -The type, a 64-bit bit-mask in host order, consists of the following +record number, both in network-byte order. +The typet bit-mask consists of the following values mapping into .Xr mdoc 7 macro identifiers: diff --git a/mandocdb.c b/mandocdb.c index 66703f23..2c03da2a 100644 --- a/mandocdb.c +++ b/mandocdb.c @@ -33,8 +33,12 @@ #include #include -#ifdef __linux__ +#if defined(__linux__) +# include # include +#elif defined(__APPLE__) +# include +# include #else # include #endif -- cgit