1323124Sdes/* $Id: mandoc_ohash.c,v 1.2 2015/10/19 18:58:47 schwarze Exp $ */ 298675Sdes/* 398675Sdes * Copyright (c) 2014, 2015 Ingo Schwarze <schwarze@openbsd.org> 498675Sdes * 598675Sdes * Permission to use, copy, modify, and distribute this software for any 698675Sdes * purpose with or without fee is hereby granted, provided that the above 798675Sdes * copyright notice and this permission notice appear in all copies. 898675Sdes * 998675Sdes * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL WARRANTIES 1098675Sdes * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 1198675Sdes * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR 1298675Sdes * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 1398675Sdes * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 1498675Sdes * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 1598675Sdes * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 1698675Sdes */ 1798675Sdes#include <sys/types.h> 1898675Sdes#include <stddef.h> 1998675Sdes#include <stdint.h> 2098675Sdes#include <stdlib.h> 2198675Sdes 2298675Sdes#include "mandoc_aux.h" 2398675Sdes#include "mandoc_ohash.h" 2498675Sdes 2598675Sdesstatic void *hash_alloc(size_t, void *); 2698675Sdesstatic void *hash_calloc(size_t, size_t, void *); 2798675Sdesstatic void hash_free(void *, void *); 2898675Sdes 29162852Sdes 30162852Sdesvoid 3198675Sdesmandoc_ohash_init(struct ohash *h, unsigned int sz, ptrdiff_t ko) 32164146Sdes{ 33164146Sdes struct ohash_info info; 34164146Sdes 3598675Sdes info.alloc = hash_alloc; 36162852Sdes info.calloc = hash_calloc; 37162852Sdes info.free = hash_free; 38162852Sdes info.data = NULL; 39162852Sdes info.key_offset = ko; 40295367Sdes 41295367Sdes ohash_init(h, sz, &info); 42295367Sdes} 43295367Sdes 44295367Sdesstatic void * 45295367Sdeshash_alloc(size_t sz, void *arg) 46295367Sdes{ 47295367Sdes 4898675Sdes return mandoc_malloc(sz); 4998675Sdes} 5098675Sdes 51181111Sdesstatic void * 52137015Sdeshash_calloc(size_t n, size_t sz, void *arg) 5398675Sdes{ 5498937Sdes 5598675Sdes return mandoc_calloc(n, sz); 5698937Sdes} 57180989Sdes 58180989Sdesstatic void 59180989Sdeshash_free(void *p, void *arg) 60180989Sdes{ 6198937Sdes 6298937Sdes free(p); 63192595Sdes} 64192595Sdes