138451Smsmith/* 238451Smsmith * Copyright (c) 1988, 1993 338451Smsmith * The Regents of the University of California. All rights reserved. 438451Smsmith * 538451Smsmith * Redistribution and use in source and binary forms, with or without 638451Smsmith * modification, are permitted provided that the following conditions 738451Smsmith * are met: 838451Smsmith * 1. Redistributions of source code must retain the above copyright 938451Smsmith * notice, this list of conditions and the following disclaimer. 1038451Smsmith * 2. Redistributions in binary form must reproduce the above copyright 1138451Smsmith * notice, this list of conditions and the following disclaimer in the 1238451Smsmith * documentation and/or other materials provided with the distribution. 1338451Smsmith * 4. Neither the name of the University nor the names of its contributors 1438451Smsmith * may be used to endorse or promote products derived from this software 1538451Smsmith * without specific prior written permission. 1638451Smsmith * 1738451Smsmith * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 1838451Smsmith * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1938451Smsmith * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2038451Smsmith * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 2138451Smsmith * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2238451Smsmith * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2338451Smsmith * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2438451Smsmith * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2538451Smsmith * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2638451Smsmith * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2738451Smsmith * SUCH DAMAGE. 2838451Smsmith */ 2938451Smsmith 3084221Sdillon#include <sys/cdefs.h> 3184221Sdillon__FBSDID("$FreeBSD$"); 3284221Sdillon 3338451Smsmith#if defined(LIBC_SCCS) && !defined(lint) 3438451Smsmithstatic char sccsid[] = "@(#)strdup.c 8.1 (Berkeley) 6/4/93"; 3538451Smsmith#endif /* LIBC_SCCS and not lint */ 3638451Smsmith 3738451Smsmith#include "stand.h" 3838451Smsmith#include <stddef.h> 3938451Smsmith#include <string.h> 4038451Smsmith 4138451Smsmithchar * 4238451Smsmithstrdup(str) 4338451Smsmith const char *str; 4438451Smsmith{ 4538451Smsmith size_t len; 4638451Smsmith char *copy = NULL; 4738451Smsmith 4838451Smsmith if (str != NULL) { 4938451Smsmith len = strlen(str) + 1; 5038451Smsmith if ((copy = malloc(len)) == NULL) 5138451Smsmith return (NULL); 5238451Smsmith memcpy(copy, str, len); 5338451Smsmith } 5438451Smsmith return (copy); 5538451Smsmith} 56