1*2e8d1edaSArun Thomas /* $OpenBSD: ohash_create_entry.c,v 1.2 2004/06/22 20:00:16 espie Exp $ */
2*2e8d1edaSArun Thomas /* ex:ts=8 sw=4:
3*2e8d1edaSArun Thomas */
4*2e8d1edaSArun Thomas
5*2e8d1edaSArun Thomas /* Copyright (c) 1999, 2004 Marc Espie <espie@openbsd.org>
6*2e8d1edaSArun Thomas *
7*2e8d1edaSArun Thomas * Permission to use, copy, modify, and distribute this software for any
8*2e8d1edaSArun Thomas * purpose with or without fee is hereby granted, provided that the above
9*2e8d1edaSArun Thomas * copyright notice and this permission notice appear in all copies.
10*2e8d1edaSArun Thomas *
11*2e8d1edaSArun Thomas * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12*2e8d1edaSArun Thomas * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13*2e8d1edaSArun Thomas * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14*2e8d1edaSArun Thomas * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15*2e8d1edaSArun Thomas * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16*2e8d1edaSArun Thomas * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17*2e8d1edaSArun Thomas * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18*2e8d1edaSArun Thomas */
19*2e8d1edaSArun Thomas
20*2e8d1edaSArun Thomas #include "ohash_int.h"
21*2e8d1edaSArun Thomas
22*2e8d1edaSArun Thomas /* This handles the common case of variable length keys, where the
23*2e8d1edaSArun Thomas * key is stored at the end of the record.
24*2e8d1edaSArun Thomas */
25*2e8d1edaSArun Thomas void *
ohash_create_entry(struct ohash_info * i,const char * start,const char ** end)26*2e8d1edaSArun Thomas ohash_create_entry(struct ohash_info *i, const char *start, const char **end)
27*2e8d1edaSArun Thomas {
28*2e8d1edaSArun Thomas char *p;
29*2e8d1edaSArun Thomas
30*2e8d1edaSArun Thomas if (!*end)
31*2e8d1edaSArun Thomas *end = start + strlen(start);
32*2e8d1edaSArun Thomas p = (i->alloc)(i->key_offset + (*end - start) + 1, i->data);
33*2e8d1edaSArun Thomas if (p) {
34*2e8d1edaSArun Thomas memcpy(p+i->key_offset, start, *end-start);
35*2e8d1edaSArun Thomas p[i->key_offset + (*end - start)] = '\0';
36*2e8d1edaSArun Thomas }
37*2e8d1edaSArun Thomas return (void *)p;
38*2e8d1edaSArun Thomas }
39