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