196c4266cSRobert Watson /*- 296c4266cSRobert Watson * Copyright (c) 2003 Networks Associates Technology, Inc. 396c4266cSRobert Watson * All rights reserved. 496c4266cSRobert Watson * 596c4266cSRobert Watson * This software was developed for the FreeBSD Project by NAI Labs, 696c4266cSRobert Watson * the Security Research Division of Network Associates, Inc. under 796c4266cSRobert Watson * DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"), as part of the DARPA 896c4266cSRobert Watson * CHATS research program. 996c4266cSRobert Watson * 1096c4266cSRobert Watson * Redistribution and use in source and binary forms, with or without 1196c4266cSRobert Watson * modification, are permitted provided that the following conditions 1296c4266cSRobert Watson * are met: 1396c4266cSRobert Watson * 1. Redistributions of source code must retain the above copyright 1496c4266cSRobert Watson * notice, this list of conditions and the following disclaimer. 1596c4266cSRobert Watson * 2. Redistributions in binary form must reproduce the above copyright 1696c4266cSRobert Watson * notice, this list of conditions and the following disclaimer in the 1796c4266cSRobert Watson * documentation and/or other materials provided with the distribution. 1896c4266cSRobert Watson * 3. The names of the authors may not be used to endorse or promote 1996c4266cSRobert Watson * products derived from this software without specific prior written 2096c4266cSRobert Watson * permission. 2196c4266cSRobert Watson * 2296c4266cSRobert Watson * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 2396c4266cSRobert Watson * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2496c4266cSRobert Watson * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2596c4266cSRobert Watson * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 2696c4266cSRobert Watson * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2796c4266cSRobert Watson * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2896c4266cSRobert Watson * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2996c4266cSRobert Watson * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 3096c4266cSRobert Watson * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 3196c4266cSRobert Watson * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3296c4266cSRobert Watson * SUCH DAMAGE. 3396c4266cSRobert Watson * 3496c4266cSRobert Watson * $FreeBSD$ 3596c4266cSRobert Watson */ 3696c4266cSRobert Watson 3796c4266cSRobert Watson #include <sys/param.h> 3896c4266cSRobert Watson #include <sys/kernel.h> 3996c4266cSRobert Watson #include <sys/libkern.h> 4096c4266cSRobert Watson #include <sys/malloc.h> 4196c4266cSRobert Watson 4296c4266cSRobert Watson MALLOC_DEFINE(M_STRING, "string", "string buffers"); 4396c4266cSRobert Watson 4496c4266cSRobert Watson char * 4596c4266cSRobert Watson strdup(const char *string) 4696c4266cSRobert Watson { 4796c4266cSRobert Watson size_t len; 4896c4266cSRobert Watson char *copy; 4996c4266cSRobert Watson 5096c4266cSRobert Watson len = strlen(string) + 1; 5196c4266cSRobert Watson copy = malloc(len, M_STRING, M_WAITOK); 5296c4266cSRobert Watson bcopy(string, copy, len); 5396c4266cSRobert Watson return (copy); 5496c4266cSRobert Watson } 55