xref: /illumos-gate/usr/src/cmd/mandoc/mandoc_ohash.c (revision 4d131170)
1*4d131170SRobert Mustacchi /* $Id: mandoc_ohash.c,v 1.3 2020/06/22 19:20:40 schwarze Exp $	*/
2371584c2SYuri Pankov /*
3371584c2SYuri Pankov  * Copyright (c) 2014, 2015 Ingo Schwarze <schwarze@openbsd.org>
4371584c2SYuri Pankov  *
5371584c2SYuri Pankov  * Permission to use, copy, modify, and distribute this software for any
6371584c2SYuri Pankov  * purpose with or without fee is hereby granted, provided that the above
7371584c2SYuri Pankov  * copyright notice and this permission notice appear in all copies.
8371584c2SYuri Pankov  *
9371584c2SYuri Pankov  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL WARRANTIES
10371584c2SYuri Pankov  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11371584c2SYuri Pankov  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
12371584c2SYuri Pankov  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13371584c2SYuri Pankov  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14371584c2SYuri Pankov  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15371584c2SYuri Pankov  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16371584c2SYuri Pankov  */
17*4d131170SRobert Mustacchi #include "config.h"
18*4d131170SRobert Mustacchi 
19371584c2SYuri Pankov #include <sys/types.h>
20371584c2SYuri Pankov #include <stddef.h>
21371584c2SYuri Pankov #include <stdint.h>
22371584c2SYuri Pankov #include <stdlib.h>
23371584c2SYuri Pankov 
24371584c2SYuri Pankov #include "mandoc_aux.h"
25371584c2SYuri Pankov #include "mandoc_ohash.h"
26371584c2SYuri Pankov 
27371584c2SYuri Pankov static	void	 *hash_alloc(size_t, void *);
28371584c2SYuri Pankov static	void	 *hash_calloc(size_t, size_t, void *);
29371584c2SYuri Pankov static	void	  hash_free(void *, void *);
30371584c2SYuri Pankov 
31371584c2SYuri Pankov 
32371584c2SYuri Pankov void
mandoc_ohash_init(struct ohash * h,unsigned int sz,ptrdiff_t ko)33371584c2SYuri Pankov mandoc_ohash_init(struct ohash *h, unsigned int sz, ptrdiff_t ko)
34371584c2SYuri Pankov {
35371584c2SYuri Pankov 	struct ohash_info info;
36371584c2SYuri Pankov 
37371584c2SYuri Pankov 	info.alloc = hash_alloc;
38371584c2SYuri Pankov 	info.calloc = hash_calloc;
39371584c2SYuri Pankov 	info.free = hash_free;
40371584c2SYuri Pankov 	info.data = NULL;
41371584c2SYuri Pankov 	info.key_offset = ko;
42371584c2SYuri Pankov 
43371584c2SYuri Pankov 	ohash_init(h, sz, &info);
44371584c2SYuri Pankov }
45371584c2SYuri Pankov 
46371584c2SYuri Pankov static void *
hash_alloc(size_t sz,void * arg)47371584c2SYuri Pankov hash_alloc(size_t sz, void *arg)
48371584c2SYuri Pankov {
49371584c2SYuri Pankov 
50371584c2SYuri Pankov 	return mandoc_malloc(sz);
51371584c2SYuri Pankov }
52371584c2SYuri Pankov 
53371584c2SYuri Pankov static void *
hash_calloc(size_t n,size_t sz,void * arg)54371584c2SYuri Pankov hash_calloc(size_t n, size_t sz, void *arg)
55371584c2SYuri Pankov {
56371584c2SYuri Pankov 
57371584c2SYuri Pankov 	return mandoc_calloc(n, sz);
58371584c2SYuri Pankov }
59371584c2SYuri Pankov 
60371584c2SYuri Pankov static void
hash_free(void * p,void * arg)61371584c2SYuri Pankov hash_free(void *p, void *arg)
62371584c2SYuri Pankov {
63371584c2SYuri Pankov 
64371584c2SYuri Pankov 	free(p);
65371584c2SYuri Pankov }
66