xref: /freebsd/sbin/dhclient/alloc.c (revision 1d386b48a555f61cb7325543adbbb5c3f3407a66)
147c08596SBrooks Davis /*	$OpenBSD: alloc.c,v 1.9 2004/05/04 20:28:40 deraadt Exp $	*/
247c08596SBrooks Davis 
347c08596SBrooks Davis /* Memory allocation... */
447c08596SBrooks Davis 
5*8a16b7a1SPedro F. Giffuni /*-
6*8a16b7a1SPedro F. Giffuni  * SPDX-License-Identifier: BSD-3-Clause
7*8a16b7a1SPedro F. Giffuni  *
847c08596SBrooks Davis  * Copyright (c) 1995, 1996, 1998 The Internet Software Consortium.
947c08596SBrooks Davis  * All rights reserved.
1047c08596SBrooks Davis  *
1147c08596SBrooks Davis  * Redistribution and use in source and binary forms, with or without
1247c08596SBrooks Davis  * modification, are permitted provided that the following conditions
1347c08596SBrooks Davis  * are met:
1447c08596SBrooks Davis  *
1547c08596SBrooks Davis  * 1. Redistributions of source code must retain the above copyright
1647c08596SBrooks Davis  *    notice, this list of conditions and the following disclaimer.
1747c08596SBrooks Davis  * 2. Redistributions in binary form must reproduce the above copyright
1847c08596SBrooks Davis  *    notice, this list of conditions and the following disclaimer in the
1947c08596SBrooks Davis  *    documentation and/or other materials provided with the distribution.
2047c08596SBrooks Davis  * 3. Neither the name of The Internet Software Consortium nor the names
2147c08596SBrooks Davis  *    of its contributors may be used to endorse or promote products derived
2247c08596SBrooks Davis  *    from this software without specific prior written permission.
2347c08596SBrooks Davis  *
2447c08596SBrooks Davis  * THIS SOFTWARE IS PROVIDED BY THE INTERNET SOFTWARE CONSORTIUM AND
2547c08596SBrooks Davis  * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
2647c08596SBrooks Davis  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
2747c08596SBrooks Davis  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
2847c08596SBrooks Davis  * DISCLAIMED.  IN NO EVENT SHALL THE INTERNET SOFTWARE CONSORTIUM OR
2947c08596SBrooks Davis  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
3047c08596SBrooks Davis  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
3147c08596SBrooks Davis  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
3247c08596SBrooks Davis  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
3347c08596SBrooks Davis  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
3447c08596SBrooks Davis  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
3547c08596SBrooks Davis  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3647c08596SBrooks Davis  * SUCH DAMAGE.
3747c08596SBrooks Davis  *
3847c08596SBrooks Davis  * This software has been written for the Internet Software Consortium
3947c08596SBrooks Davis  * by Ted Lemon <mellon@fugue.com> in cooperation with Vixie
4047c08596SBrooks Davis  * Enterprises.  To learn more about the Internet Software Consortium,
4147c08596SBrooks Davis  * see ``http://www.vix.com/isc''.  To learn more about Vixie
4247c08596SBrooks Davis  * Enterprises, see ``http://www.vix.com''.
4347c08596SBrooks Davis  */
4447c08596SBrooks Davis 
458794fdbbSBrooks Davis #include <sys/cdefs.h>
4647c08596SBrooks Davis #include "dhcpd.h"
4747c08596SBrooks Davis 
4847c08596SBrooks Davis struct string_list *
new_string_list(size_t size)4947c08596SBrooks Davis new_string_list(size_t size)
5047c08596SBrooks Davis {
5147c08596SBrooks Davis 	struct string_list *rval;
5247c08596SBrooks Davis 
5347c08596SBrooks Davis 	rval = calloc(1, sizeof(struct string_list) + size);
5447c08596SBrooks Davis 	if (rval != NULL)
5547c08596SBrooks Davis 		rval->string = ((char *)rval) + sizeof(struct string_list);
5647c08596SBrooks Davis 	return (rval);
5747c08596SBrooks Davis }
5847c08596SBrooks Davis 
5947c08596SBrooks Davis struct hash_table *
new_hash_table(int count)6047c08596SBrooks Davis new_hash_table(int count)
6147c08596SBrooks Davis {
6247c08596SBrooks Davis 	struct hash_table *rval;
6347c08596SBrooks Davis 
6447c08596SBrooks Davis 	rval = calloc(1, sizeof(struct hash_table) -
6547c08596SBrooks Davis 	    (DEFAULT_HASH_SIZE * sizeof(struct hash_bucket *)) +
6647c08596SBrooks Davis 	    (count * sizeof(struct hash_bucket *)));
6747c08596SBrooks Davis 	if (rval == NULL)
6847c08596SBrooks Davis 		return (NULL);
6947c08596SBrooks Davis 	rval->hash_count = count;
7047c08596SBrooks Davis 	return (rval);
7147c08596SBrooks Davis }
7247c08596SBrooks Davis 
7347c08596SBrooks Davis struct hash_bucket *
new_hash_bucket(void)7447c08596SBrooks Davis new_hash_bucket(void)
7547c08596SBrooks Davis {
7647c08596SBrooks Davis 	struct hash_bucket *rval = calloc(1, sizeof(struct hash_bucket));
7747c08596SBrooks Davis 
7847c08596SBrooks Davis 	return (rval);
7947c08596SBrooks Davis }
80