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