From 4a85ade55adbd6824243118f454b17c8aa6866ca Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Tue, 29 Dec 2009 16:55:38 +0100 Subject: [PATCH] db_init: round up page size to nearest power of 2 Recent versions of db-4 seem to require the page size to be a power of 2 and will complain if it is not. --- common/db.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/common/db.c b/common/db.c index 9e375a20..fc3e851b 100644 --- a/common/db.c +++ b/common/db.c @@ -741,6 +741,18 @@ err: return 1; } +/* Round up v to the nearest power of 2 */ +static size_t round_up(size_t v) +{ + ssize_t old_v = v; + + while (v) { + old_v = v; + v ^= v & -v; + } + return old_v << 1; +} + /* * PUBLIC: int db_msg_open __P((SCR *, char *, DB **)); */ @@ -767,7 +779,7 @@ db_init(SCR *sp, EXF *ep, char *rcv_name, char *oname, size_t psize, int *open_e } ep->db->set_re_delim(ep->db, '\n'); /* Always set. */ - ep->db->set_pagesize(ep->db, psize); + ep->db->set_pagesize(ep->db, round_up(psize)); ep->db->set_flags(ep->db, DB_RENUMBER | DB_SNAPSHOT); if (rcv_name == NULL) ep->db->set_re_source(ep->db, oname); -- 2.11.4.GIT