1*9ff1f2acSchristos /* Id: mandoc_ohash.c,v 1.2 2015/10/19 18:58:47 schwarze Exp */
2*9ff1f2acSchristos /*
3*9ff1f2acSchristos * Copyright (c) 2014, 2015 Ingo Schwarze <schwarze@openbsd.org>
4*9ff1f2acSchristos *
5*9ff1f2acSchristos * Permission to use, copy, modify, and distribute this software for any
6*9ff1f2acSchristos * purpose with or without fee is hereby granted, provided that the above
7*9ff1f2acSchristos * copyright notice and this permission notice appear in all copies.
8*9ff1f2acSchristos *
9*9ff1f2acSchristos * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL WARRANTIES
10*9ff1f2acSchristos * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11*9ff1f2acSchristos * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
12*9ff1f2acSchristos * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13*9ff1f2acSchristos * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14*9ff1f2acSchristos * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15*9ff1f2acSchristos * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16*9ff1f2acSchristos */
17*9ff1f2acSchristos #include <sys/types.h>
18*9ff1f2acSchristos #include <stddef.h>
19*9ff1f2acSchristos #include <stdint.h>
20*9ff1f2acSchristos #include <stdlib.h>
21*9ff1f2acSchristos
22*9ff1f2acSchristos #include "mandoc_aux.h"
23*9ff1f2acSchristos #include "mandoc_ohash.h"
24*9ff1f2acSchristos
25*9ff1f2acSchristos static void *hash_alloc(size_t, void *);
26*9ff1f2acSchristos static void *hash_calloc(size_t, size_t, void *);
27*9ff1f2acSchristos static void hash_free(void *, void *);
28*9ff1f2acSchristos
29*9ff1f2acSchristos
30*9ff1f2acSchristos void
mandoc_ohash_init(struct ohash * h,unsigned int sz,ptrdiff_t ko)31*9ff1f2acSchristos mandoc_ohash_init(struct ohash *h, unsigned int sz, ptrdiff_t ko)
32*9ff1f2acSchristos {
33*9ff1f2acSchristos struct ohash_info info;
34*9ff1f2acSchristos
35*9ff1f2acSchristos info.alloc = hash_alloc;
36*9ff1f2acSchristos info.calloc = hash_calloc;
37*9ff1f2acSchristos info.free = hash_free;
38*9ff1f2acSchristos info.data = NULL;
39*9ff1f2acSchristos info.key_offset = ko;
40*9ff1f2acSchristos
41*9ff1f2acSchristos ohash_init(h, sz, &info);
42*9ff1f2acSchristos }
43*9ff1f2acSchristos
44*9ff1f2acSchristos static void *
hash_alloc(size_t sz,void * arg)45*9ff1f2acSchristos hash_alloc(size_t sz, void *arg)
46*9ff1f2acSchristos {
47*9ff1f2acSchristos
48*9ff1f2acSchristos return mandoc_malloc(sz);
49*9ff1f2acSchristos }
50*9ff1f2acSchristos
51*9ff1f2acSchristos static void *
hash_calloc(size_t n,size_t sz,void * arg)52*9ff1f2acSchristos hash_calloc(size_t n, size_t sz, void *arg)
53*9ff1f2acSchristos {
54*9ff1f2acSchristos
55*9ff1f2acSchristos return mandoc_calloc(n, sz);
56*9ff1f2acSchristos }
57*9ff1f2acSchristos
58*9ff1f2acSchristos static void
hash_free(void * p,void * arg)59*9ff1f2acSchristos hash_free(void *p, void *arg)
60*9ff1f2acSchristos {
61*9ff1f2acSchristos
62*9ff1f2acSchristos free(p);
63*9ff1f2acSchristos }
64