1228063Sbapt/* $OpenBSD: ohash_create_entry.c,v 1.2 2004/06/22 20:00:16 espie Exp $ */ 2228063Sbapt/* ex:ts=8 sw=4: 3228063Sbapt */ 4228063Sbapt 5228063Sbapt/* Copyright (c) 1999, 2004 Marc Espie <espie@openbsd.org> 6228063Sbapt * 7228063Sbapt * Permission to use, copy, modify, and distribute this software for any 8228063Sbapt * purpose with or without fee is hereby granted, provided that the above 9228063Sbapt * copyright notice and this permission notice appear in all copies. 10228063Sbapt * 11228063Sbapt * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 12228063Sbapt * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 13228063Sbapt * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 14228063Sbapt * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 15228063Sbapt * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 16228063Sbapt * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 17228063Sbapt * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 18228063Sbapt */ 19228063Sbapt#include <sys/cdefs.h> 20228063Sbapt__FBSDID("$FreeBSD$"); 21228063Sbapt 22228063Sbapt#include "ohash_int.h" 23228063Sbapt 24228063Sbapt/* This handles the common case of variable length keys, where the 25228063Sbapt * key is stored at the end of the record. 26228063Sbapt */ 27228063Sbaptvoid * 28228063Sbaptohash_create_entry(struct ohash_info *i, const char *start, const char **end) 29228063Sbapt{ 30228063Sbapt char *p; 31228063Sbapt 32228063Sbapt if (!*end) 33228063Sbapt *end = start + strlen(start); 34228063Sbapt p = (i->alloc)(i->key_offset + (*end - start) + 1, i->data); 35228063Sbapt if (p) { 36228063Sbapt memcpy(p+i->key_offset, start, *end-start); 37228063Sbapt p[i->key_offset + (*end - start)] = '\0'; 38228063Sbapt } 39228063Sbapt return (void *)p; 40228063Sbapt} 41