13914ddf8SEdward Tomasz Napierala /*-
23914ddf8SEdward Tomasz Napierala * Copyright (c) 2003 Networks Associates Technology, Inc.
33914ddf8SEdward Tomasz Napierala * All rights reserved.
43914ddf8SEdward Tomasz Napierala *
53914ddf8SEdward Tomasz Napierala * This software was developed for the FreeBSD Project by Network
63914ddf8SEdward Tomasz Napierala * Associates Laboratories, the Security Research Division of Network
73914ddf8SEdward Tomasz Napierala * Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035
83914ddf8SEdward Tomasz Napierala * ("CBOSS"), as part of the DARPA CHATS research program.
93914ddf8SEdward Tomasz Napierala *
103914ddf8SEdward Tomasz Napierala * Redistribution and use in source and binary forms, with or without
113914ddf8SEdward Tomasz Napierala * modification, are permitted provided that the following conditions
123914ddf8SEdward Tomasz Napierala * are met:
133914ddf8SEdward Tomasz Napierala * 1. Redistributions of source code must retain the above copyright
143914ddf8SEdward Tomasz Napierala * notice, this list of conditions and the following disclaimer.
153914ddf8SEdward Tomasz Napierala * 2. Redistributions in binary form must reproduce the above copyright
163914ddf8SEdward Tomasz Napierala * notice, this list of conditions and the following disclaimer in the
173914ddf8SEdward Tomasz Napierala * documentation and/or other materials provided with the distribution.
183914ddf8SEdward Tomasz Napierala *
193914ddf8SEdward Tomasz Napierala * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
203914ddf8SEdward Tomasz Napierala * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
213914ddf8SEdward Tomasz Napierala * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
223914ddf8SEdward Tomasz Napierala * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
233914ddf8SEdward Tomasz Napierala * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
243914ddf8SEdward Tomasz Napierala * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
253914ddf8SEdward Tomasz Napierala * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
263914ddf8SEdward Tomasz Napierala * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
273914ddf8SEdward Tomasz Napierala * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
283914ddf8SEdward Tomasz Napierala * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
293914ddf8SEdward Tomasz Napierala * SUCH DAMAGE.
303914ddf8SEdward Tomasz Napierala */
313914ddf8SEdward Tomasz Napierala
323914ddf8SEdward Tomasz Napierala #include <sys/param.h>
333914ddf8SEdward Tomasz Napierala #include <sys/kernel.h>
343914ddf8SEdward Tomasz Napierala #include <sys/libkern.h>
353914ddf8SEdward Tomasz Napierala #include <sys/malloc.h>
363914ddf8SEdward Tomasz Napierala
373914ddf8SEdward Tomasz Napierala char *
strndup(const char * string,size_t maxlen,struct malloc_type * type)383914ddf8SEdward Tomasz Napierala strndup(const char *string, size_t maxlen, struct malloc_type *type)
393914ddf8SEdward Tomasz Napierala {
403914ddf8SEdward Tomasz Napierala size_t len;
413914ddf8SEdward Tomasz Napierala char *copy;
423914ddf8SEdward Tomasz Napierala
433914ddf8SEdward Tomasz Napierala len = strnlen(string, maxlen) + 1;
443914ddf8SEdward Tomasz Napierala copy = malloc(len, type, M_WAITOK);
45*90a3b6a7SZhenlei Huang memcpy(copy, string, len);
463914ddf8SEdward Tomasz Napierala copy[len - 1] = '\0';
473914ddf8SEdward Tomasz Napierala return (copy);
483914ddf8SEdward Tomasz Napierala }
49