Date: Thu, 14 Aug 2014 22:23:55 GMT From: ghostmansd@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r272445 - in soc2014/ghostmansd/head: contrib/colldb lib/libc lib/libc/locale lib/libc/string lib/libc/unicode lib/libcolldb Message-ID: <201408142223.s7EMNtDk011325@socsvn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: ghostmansd Date: Thu Aug 14 22:23:54 2014 New Revision: 272445 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=272445 Log: changing fallback behaviour; deprecating _UNICODE_SOURCE Added: soc2014/ghostmansd/head/lib/libcolldb/colldb - copied, changed from r272296, soc2014/ghostmansd/head/contrib/colldb/colldb soc2014/ghostmansd/head/lib/libcolldb/colldb.c - copied unchanged from r272296, soc2014/ghostmansd/head/contrib/colldb/colldb.c soc2014/ghostmansd/head/lib/libcolldb/colldb.h - copied unchanged from r272296, soc2014/ghostmansd/head/contrib/colldb/colldb.h Deleted: soc2014/ghostmansd/head/contrib/colldb/ Modified: soc2014/ghostmansd/head/lib/libc/Makefile soc2014/ghostmansd/head/lib/libc/locale/collate.c soc2014/ghostmansd/head/lib/libc/locale/xlocale.c soc2014/ghostmansd/head/lib/libc/locale/xlocale_private.h soc2014/ghostmansd/head/lib/libc/string/wcscoll.c soc2014/ghostmansd/head/lib/libc/string/wcsxfrm.c soc2014/ghostmansd/head/lib/libc/unicode/ucscoll.c soc2014/ghostmansd/head/lib/libcolldb/Makefile Modified: soc2014/ghostmansd/head/lib/libc/Makefile ============================================================================== --- soc2014/ghostmansd/head/lib/libc/Makefile Thu Aug 14 21:43:20 2014 (r272444) +++ soc2014/ghostmansd/head/lib/libc/Makefile Thu Aug 14 22:23:54 2014 (r272445) @@ -94,10 +94,7 @@ .include "${LIBC_SRCTOP}/stdlib/jemalloc/Makefile.inc" .include "${LIBC_SRCTOP}/stdtime/Makefile.inc" .include "${LIBC_SRCTOP}/string/Makefile.inc" -.ifdef UNICODE -CFLAGS+= -D_UNICODE_SOURCE .include "${LIBC_SRCTOP}/unicode/Makefile.inc" -.endif .include "${LIBC_SRCTOP}/sys/Makefile.inc" .include "${LIBC_SRCTOP}/rpc/Makefile.inc" .include "${LIBC_SRCTOP}/uuid/Makefile.inc" Modified: soc2014/ghostmansd/head/lib/libc/locale/collate.c ============================================================================== --- soc2014/ghostmansd/head/lib/libc/locale/collate.c Thu Aug 14 21:43:20 2014 (r272444) +++ soc2014/ghostmansd/head/lib/libc/locale/collate.c Thu Aug 14 22:23:54 2014 (r272445) @@ -41,6 +41,12 @@ #include <errno.h> #include <unistd.h> #include <sysexits.h> + +#include <sys/types.h> +#include <db.h> +#include <fcntl.h> +#include <limits.h> + #include "un-namespace.h" #include "collate.h" @@ -50,39 +56,12 @@ #include "libc_private.h" -#ifdef _UNICODE_SOURCE -#include <sys/types.h> -#include <db.h> -#include <fcntl.h> -#include <limits.h> -#include <pthread.h> - - struct __colldb { uint32_t version; void *handle; }; -static void *handle = NULL; -static pthread_once_t once = PTHREAD_ONCE_INIT; - - -static void -__colldb_root_init(void) -{ - handle = __colldb_open("/usr/share/colldb/root.db"); -} - - -void * -__colldb_root_handle(void) -{ - pthread_once(&once, &__colldb_root_init); - return (handle); -} - - void * __colldb_create(const char *path, int mode) { @@ -360,7 +339,6 @@ } return state; } -#endif /* Modified: soc2014/ghostmansd/head/lib/libc/locale/xlocale.c ============================================================================== --- soc2014/ghostmansd/head/lib/libc/locale/xlocale.c Thu Aug 14 21:43:20 2014 (r272444) +++ soc2014/ghostmansd/head/lib/libc/locale/xlocale.c Thu Aug 14 22:23:54 2014 (r272445) @@ -36,6 +36,24 @@ #include "libc_private.h" #include "xlocale_private.h" + +/* Collation Database implementation. */ +static void *colldb_root_handle = NULL; +static pthread_once_t colldb_root_once = PTHREAD_ONCE_INIT; + +static void colldb_root_init(void) +{ + colldb_root_handle = + __colldb_open("/usr/share/locale/UTF-8/LC_COLLATE"); +} + +void *__colldb_root_handle(void) +{ + _once(&colldb_root_once, &colldb_root_init); + return (colldb_root_handle); +} + + /** * Each locale loader declares a global component. This is used by setlocale() * and also by xlocale with LC_GLOBAL_LOCALE.. @@ -81,9 +99,7 @@ &__xlocale_global_time, &__xlocale_global_messages }, -#ifdef _UNICODE_SOURCE NULL, -#endif 1, 0, 1, @@ -97,9 +113,7 @@ &__xlocale_C_ctype, 0, 0, 0, 0 }, -#ifdef _UNICODE_SOURCE NULL, -#endif 1, 0, 1, Modified: soc2014/ghostmansd/head/lib/libc/locale/xlocale_private.h ============================================================================== --- soc2014/ghostmansd/head/lib/libc/locale/xlocale_private.h Thu Aug 14 21:43:20 2014 (r272444) +++ soc2014/ghostmansd/head/lib/libc/locale/xlocale_private.h Thu Aug 14 22:23:54 2014 (r272445) @@ -38,12 +38,8 @@ #include <stdint.h> #include <sys/types.h> #include <machine/atomic.h> -#include "setlocale.h" - - -#ifdef _UNICODE_SOURCE -#include <stdint.h> #include <unistd.h> +#include "setlocale.h" /* Unicode canonicalization. */ int __uccclass(uint32_t); @@ -89,7 +85,6 @@ size_t __ucsxfrm(uint32_t*, const uint32_t*, size_t, void*); int __ucscoll(const uint32_t*, const uint32_t*, void*); -#endif enum { @@ -137,10 +132,8 @@ struct xlocale_refcounted header; /** Components for the locale. */ struct xlocale_component *components[XLC_LAST]; -#ifdef _UNICODE_SOURCE /** Collation Database handle. */ void *colldb; -#endif /** Flag indicating if components[XLC_MONETARY] has changed since the * last call to localeconv_l() with this locale. */ int monetary_locale_changed; Modified: soc2014/ghostmansd/head/lib/libc/string/wcscoll.c ============================================================================== --- soc2014/ghostmansd/head/lib/libc/string/wcscoll.c Thu Aug 14 21:43:20 2014 (r272444) +++ soc2014/ghostmansd/head/lib/libc/string/wcscoll.c Thu Aug 14 22:23:54 2014 (r272445) @@ -41,7 +41,9 @@ #include <wchar.h> #include "collate.h" -#ifndef _UNICODE_SOURCE +#include <stdio.h> + + static char * __mbsdup(const wchar_t *ws) { @@ -62,24 +64,24 @@ return (mbs); } -#endif + int wcscoll_l(const wchar_t *ws1, const wchar_t *ws2, locale_t locale) { -#ifdef _UNICODE_SOURCE - const uint32_t *ucs1 = (const uint32_t*)ws1; - const uint32_t *ucs2 = (const uint32_t*)ws2; - - return __ucscoll(ucs1, ucs2, locale->colldb); - -#else /* !_UNICODE_SOURCE */ char *mbs1, *mbs2; int diff, sverrno; FIX_LOCALE(locale); + const int init_error = errno; + const uint32_t *ucs1 = (const uint32_t*)ws1; + const uint32_t *ucs2 = (const uint32_t*)ws2; struct xlocale_collate *table = (struct xlocale_collate*)locale->components[XLC_COLLATE]; + diff = __ucscoll(ucs1, ucs2, locale->colldb); + if (errno == init_error) + return diff; + if (table->__collate_load_error || MB_CUR_MAX > 1) /* * Locale has no special collating order, could not be @@ -108,7 +110,6 @@ errno = sverrno; return (diff); -#endif } int Modified: soc2014/ghostmansd/head/lib/libc/string/wcsxfrm.c ============================================================================== --- soc2014/ghostmansd/head/lib/libc/string/wcsxfrm.c Thu Aug 14 21:43:20 2014 (r272444) +++ soc2014/ghostmansd/head/lib/libc/string/wcsxfrm.c Thu Aug 14 22:23:54 2014 (r272445) @@ -47,19 +47,21 @@ size_t wcsxfrm_l(wchar_t * __restrict dest, const wchar_t * __restrict src, size_t len, locale_t locale) { -#ifdef _UNICODE_SOURCE - uint32_t *udst = (uint32_t*)dest; - const uint32_t *usrc = (const uint32_t*)src; - - return __ucsxfrm(udst, usrc, len, locale->colldb); -#else int prim, sec, l; size_t slen; char *mbsrc, *s, *ss; FIX_LOCALE(locale); + uint32_t *udst = NULL; + size_t ulen = 0; + const int init_error = errno; + const uint32_t *usrc = (const uint32_t*)src; struct xlocale_collate *table = (struct xlocale_collate*)locale->components[XLC_COLLATE]; + ulen = __ucsxfrm(udst, usrc, len, locale->colldb); + if (errno == init_errno) + return (ulen); + if (*src == L'\0') { if (len != 0) *dest = L'\0'; @@ -103,7 +105,6 @@ *dest = L'\0'; return (slen); -#endif } size_t Modified: soc2014/ghostmansd/head/lib/libc/unicode/ucscoll.c ============================================================================== --- soc2014/ghostmansd/head/lib/libc/unicode/ucscoll.c Thu Aug 14 21:43:20 2014 (r272444) +++ soc2014/ghostmansd/head/lib/libc/unicode/ucscoll.c Thu Aug 14 22:23:54 2014 (r272445) @@ -30,6 +30,8 @@ #include "xlocale_private.h" #include "coll.h" +#include <stdio.h> + int __ucscoll(const uint32_t *lstr, const uint32_t *rstr, void *colldb) @@ -48,12 +50,14 @@ struct __colldb_weight weights[2][__COLLDB_WEIGHTS_MAX]; const int init_error = errno; + fprintf(stderr, "ucscoll\n"); if ((lstr == NULL) || (rstr == NULL)) { errno = EINVAL; return (0); } if (colldb == NULL) colldb = __colldb_root; + fprintf(stderr, "root=%p\n", colldb); for (i = 0; i < 2; ++i) { size[i] = __ucsnorm(NULL, str[i], 0, __UC_NFD); norm[i] = malloc(size[i] * sizeof(uint32_t)); Modified: soc2014/ghostmansd/head/lib/libcolldb/Makefile ============================================================================== --- soc2014/ghostmansd/head/lib/libcolldb/Makefile Thu Aug 14 21:43:20 2014 (r272444) +++ soc2014/ghostmansd/head/lib/libcolldb/Makefile Thu Aug 14 22:23:54 2014 (r272445) @@ -1,6 +1,4 @@ -COLLDB= $(.CURDIR}/../../contrib/colldb -.PATH: ${COLLDB} - +SHLIBDIR?= /usr/lib LIB= colldb SRCS= colldb.c INCS= colldb.h Copied and modified: soc2014/ghostmansd/head/lib/libcolldb/colldb (from r272296, soc2014/ghostmansd/head/contrib/colldb/colldb) ============================================================================== --- soc2014/ghostmansd/head/contrib/colldb/colldb Tue Aug 12 17:29:20 2014 (r272296, copy source) +++ soc2014/ghostmansd/head/lib/libcolldb/colldb Thu Aug 14 22:23:54 2014 (r272445) @@ -15,8 +15,7 @@ __maintainer__ = "Dmitry Selyutin" -#_dll_ = ctypes.CDLL("libcolldb.so") -_dll_ = ctypes.CDLL("./colldb.so") +_dll_ = ctypes.CDLL("libcolldb.so") class _CollDB_Weight_(ctypes.Structure): Copied: soc2014/ghostmansd/head/lib/libcolldb/colldb.c (from r272296, soc2014/ghostmansd/head/contrib/colldb/colldb.c) ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2014/ghostmansd/head/lib/libcolldb/colldb.c Thu Aug 14 22:23:54 2014 (r272445, copy of r272296, soc2014/ghostmansd/head/contrib/colldb/colldb.c) @@ -0,0 +1,345 @@ +/*- + * Copyright (c) 2014 Dmitry Selyutin. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include <errno.h> +#include <stdlib.h> +#include <string.h> +#include <arpa/inet.h> +#include "colldb.h" + + +struct colldb { + uint32_t version; + void *handle; +}; + + +void * +colldb_create(const char *path, int mode) +{ + DBT key; + DBT value; + DB *db = NULL; + int error = 0; + void *colldb = NULL; + uint32_t version = 0; + int flags = (O_RDWR | O_CREAT | O_TRUNC); + + colldb = calloc(1, sizeof(struct colldb)); + if (colldb == NULL) + { + errno = ENOMEM; + return (NULL); + } + db = dbopen(path, flags, mode, DB_HASH, NULL); + if (db == NULL) + { + error = errno; + free(colldb); + errno = error; + return (NULL); + } + ((struct colldb*)colldb)->version = COLLDB_VERSION; + + key.data = "TYPE"; + value.data = "COLLATION"; + key.size = (strlen("TYPE") + 1); + value.size = (strlen("COLLATION") + 1); + if (db->put(db, &key, &value, 0) == -1) + { + error = errno; + goto failure; + } + + key.data = "VERSION"; + version = htonl(((struct colldb*)colldb)->version); + value.data = &version; + key.size = (strlen("VERSION") + 1); + value.size = sizeof(((struct colldb*)colldb)->version); + if (db->put(db, &key, &value, 0) == -1) + { + error = errno; + goto failure; + } + + ((struct colldb*)colldb)->handle = db; + return (colldb); + +failure: + (void) db->close(db); + free(colldb); + errno = error; + return (NULL); +} + + +void * +colldb_open(const char *path) +{ + DBT key; + DBT value; + DB *db = NULL; + int error = 0; + int state = 0; + void *colldb = NULL; + int flags = O_RDONLY; + + colldb = calloc(1, sizeof(struct colldb)); + if (colldb == NULL) + { + errno = ENOMEM; + return (NULL); + } + db = dbopen(path, flags, 0, DB_HASH, NULL); + if (db == NULL) + { + error = errno; + free(colldb); + errno = error; + return (NULL); + } + + key.data = "TYPE"; + key.size = (strlen("TYPE") + 1); + state = db->get(db, &key, &value, 0); + if (state != 0) + { + if (state < 0) + error = errno; + else + error = EFTYPE; + goto failure; + } + if (strcmp(value.data, "COLLATION") != 0) + { + error = EFTYPE; + goto failure; + } + + key.data = "VERSION"; + key.size = (strlen("VERSION") + 1); + state = db->get(db, &key, &value, 0); + if (state != 0) + { + if (state < 0) + error = errno; + else + error = EFTYPE; + goto failure; + } + ((struct colldb*)colldb)->version = + ntohl(*(const uint32_t*)value.data); + + ((struct colldb*)colldb)->handle = db; + return (colldb); + +failure: + (void) db->close(db); + free(colldb); + errno = error; + return (NULL); +} + + +int +colldb_close(void *colldb) +{ + DB *db = NULL; + int error = 0; + + if (colldb == NULL) + { + errno = EINVAL; + return (-1); + } + db = ((struct colldb*)colldb)->handle; + if (db == NULL) + { + errno = EINVAL; + return (-1); + } + if (db->close(db) == -1) + { + error = errno; + free(colldb); + errno = error; + return (-1); + } + free(colldb); + return (0); +} + + +int +colldb_sync(void *colldb) +{ + DB *db = NULL; + + if (colldb == NULL) + { + errno = EINVAL; + return (-1); + } + db = ((struct colldb*)colldb)->handle; + if (db == NULL) + { + errno = EINVAL; + return (-1); + } + return db->sync(db, 0); +} + + +int +colldb_get(void *colldb, + struct colldb_key *key, + struct colldb_value *value) +{ + DBT dbkey; + DBT dbvalue; + DB *db = NULL; + size_t i = 0; + int state = 0; + uint32_t *keybuf = NULL; + struct colldb_weight *weights = NULL; + + if ((colldb == NULL) || (key == NULL) || (value == NULL)) + { + errno = EINVAL; + return (-1); + } + db = ((struct colldb*)colldb)->handle; + if ((db == NULL) || (key->chars == NULL) || (key->count == 0)) + { + errno = EINVAL; + return (-1); + } + + keybuf = key->chars; + if (__BYTE_ORDER__ != __ORDER_BIG_ENDIAN__) + { + keybuf = malloc(key->count * sizeof(*key->chars)); + if (keybuf == NULL) + { + errno = ENOMEM; + return (-1); + } + for (i = 0; i < key->count; ++i) + keybuf[i] = htonl(key->chars[i]); + } + + dbkey.data = keybuf; + dbkey.size = (key->count * sizeof(*key->chars)); + state = db->get(db, &dbkey, &dbvalue, 0); + if (state != 0) + return (state); + + weights = dbvalue.data; + if ((dbvalue.size / sizeof(*weights)) > value->count) + { + if (__BYTE_ORDER__ != __ORDER_BIG_ENDIAN__) + free(keybuf); + errno = ERANGE; + return (-1); + } + value->count = (dbvalue.size / sizeof(*weights)); + for (i = 0; i < value->count; ++i) + { + value->weights[i].alternate = weights[i].alternate; + value->weights[i].level1 = ntohl(weights[i].level1); + value->weights[i].level2 = ntohl(weights[i].level2); + value->weights[i].level3 = ntohl(weights[i].level3); + value->weights[i].level4 = ntohl(weights[i].level4); + } + if (__BYTE_ORDER__ != __ORDER_BIG_ENDIAN__) + free(keybuf); + return (0); +} + + +int +colldb_put(void *colldb, + struct colldb_key *key, + struct colldb_value *value) +{ + DBT dbkey; + DBT dbvalue; + DB *db = NULL; + size_t i = 0; + int state = 0; + int error = 0; + uint32_t *keybuf = NULL; + struct colldb_weight *valuebuf = NULL; + + if ((colldb == NULL) || (key == NULL) || (value == NULL)) + { + errno = EINVAL; + return (-1); + } + db = ((struct colldb*)colldb)->handle; + if ((db == NULL) || (key->chars == NULL) || (key->count == 0)) + { + errno = EINVAL; + return (-1); + } + + keybuf = key->chars; + valuebuf = value->weights; + if (__BYTE_ORDER__ != __ORDER_BIG_ENDIAN__) + { + keybuf = malloc(key->count * sizeof(*key->chars)); + valuebuf = malloc(value->count * sizeof(*value->weights)); + if ((keybuf == NULL) || (valuebuf == NULL)) + { + errno = ENOMEM; + return (-1); + } + for (i = 0; i < key->count; ++i) + keybuf[i] = htonl(key->chars[i]); + for (i = 0; i < value->count; ++i) + { + valuebuf[i].alternate = value->weights[i].alternate; + valuebuf[i].level1 = htonl(value->weights[i].level1); + valuebuf[i].level2 = htonl(value->weights[i].level2); + valuebuf[i].level3 = htonl(value->weights[i].level3); + valuebuf[i].level4 = htonl(value->weights[i].level4); + } + } + + dbkey.data = keybuf; + dbvalue.data = valuebuf; + dbkey.size = (key->count * sizeof(*key->chars)); + dbvalue.size = (value->count * sizeof(*value->weights)); + state = db->put(db, &dbkey, &dbvalue, 0); + if (__BYTE_ORDER__ != __ORDER_BIG_ENDIAN__) + { + error = errno; + free(keybuf); + free(valuebuf); + errno = error; + } + return state; +} Copied: soc2014/ghostmansd/head/lib/libcolldb/colldb.h (from r272296, soc2014/ghostmansd/head/contrib/colldb/colldb.h) ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2014/ghostmansd/head/lib/libcolldb/colldb.h Thu Aug 14 22:23:54 2014 (r272445, copy of r272296, soc2014/ghostmansd/head/contrib/colldb/colldb.h) @@ -0,0 +1,94 @@ +/*- + * Copyright (c) 2014 Dmitry Selyutin. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DECOMPOSITION, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef _COLLDB_H_ +#define _COLLDB_H_ + + +/* + * Unicode Collation Database + * Database is a map of struct colldb_key and struct colldb_value pairs, + * where each uint32_t integer is stored in network byte order. Conversion + * between host and network byte order is done implicitly. + * Each database must contain at least "TYPE" and "VERSION" keys, where + * the first one must always be "COLLATION", the last one must be a version + * as unsigned 32-bit integer. When use creates a new collation database, + * these keys are initialized automatically. + * + * colldb_put() accepts database, key and value. If necessary, it converts + * key and value into the network byte order before writing. + * + * colldb_get() accepts database, key and value. Key is converted to network + * byte order if necessary. Fields of struct colldb_value must be already + * correctly initialized, since value from database is written directly to it. + * Usually it is enough to allocate COLLDB_WEIGHTS_MAX weights. However, + * in order to support exotic databases, colldb_get() may return -1 and set + * errno to ERANGE to indicate that struct colldb_value must allocate + * a larger weights buffer. + */ + +#include <stdint.h> +#include <sys/types.h> +#include <db.h> +#include <fcntl.h> +#include <limits.h> + + +#define COLLDB_VERSION 0x00000001 +#define COLLDB_WEIGHTS_MAX 10 + +struct colldb_weight { + uint8_t alternate; + uint32_t level1; + uint32_t level2; + uint32_t level3; + uint32_t level4; +}; + +struct colldb_key { + size_t count; + uint32_t *chars; +}; + +struct colldb_value { + size_t count; + struct colldb_weight *weights; +}; + + +void* colldb_create(const char*, int mode); +void* colldb_open(const char*); +int colldb_close(void*); +int colldb_sync(void*); +int colldb_get(void*, + struct colldb_key*, + struct colldb_value*); +int colldb_put(void*, + struct colldb_key*, + struct colldb_value*); + + +#endif
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201408142223.s7EMNtDk011325>