11.3Skiyohara/* $NetBSD: strdup.c,v 1.3 2009/07/20 04:59:03 kiyohara Exp $ */ 21.1Scherry 31.1Scherry/* 41.1Scherry * Copyright (c) 1988, 1993 51.1Scherry * The Regents of the University of California. All rights reserved. 61.1Scherry * 71.1Scherry * Redistribution and use in source and binary forms, with or without 81.1Scherry * modification, are permitted provided that the following conditions 91.1Scherry * are met: 101.1Scherry * 1. Redistributions of source code must retain the above copyright 111.1Scherry * notice, this list of conditions and the following disclaimer. 121.1Scherry * 2. Redistributions in binary form must reproduce the above copyright 131.1Scherry * notice, this list of conditions and the following disclaimer in the 141.1Scherry * documentation and/or other materials provided with the distribution. 151.1Scherry * 3. All advertising materials mentioning features or use of this software 161.1Scherry * must display the following acknowledgement: 171.1Scherry * This product includes software developed by the University of 181.1Scherry * California, Berkeley and its contributors. 191.1Scherry * 4. Neither the name of the University nor the names of its contributors 201.1Scherry * may be used to endorse or promote products derived from this software 211.1Scherry * without specific prior written permission. 221.1Scherry * 231.1Scherry * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 241.1Scherry * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 251.1Scherry * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 261.1Scherry * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 271.1Scherry * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 281.1Scherry * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 291.1Scherry * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 301.1Scherry * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 311.1Scherry * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 321.1Scherry * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 331.1Scherry * SUCH DAMAGE. 341.1Scherry */ 351.1Scherry 361.1Scherry#include <sys/cdefs.h> 371.1Scherry 381.1Scherry#if defined(LIBC_SCCS) && !defined(lint) 391.1Scherrystatic char sccsid[] = "@(#)strdup.c 8.1 (Berkeley) 6/4/93"; 401.1Scherry#endif /* LIBC_SCCS and not lint */ 411.1Scherry 421.1Scherry#include <lib/libsa/stand.h> 431.3Skiyohara#include <lib/libsa/loadfile.h> 441.1Scherry#include <lib/libkern/libkern.h> 451.1Scherry 461.1Scherry#include "bootstrap.h" 471.1Scherry 481.1Scherry 491.1Scherrychar * 501.2Sdslstrdup(const char *str) 511.1Scherry{ 521.1Scherry size_t len; 531.1Scherry char *copy = NULL; 541.1Scherry 551.1Scherry if (str != NULL) { 561.1Scherry len = strlen(str) + 1; 571.1Scherry if ((copy = alloc(len)) == NULL) 581.1Scherry return (NULL); 591.1Scherry memcpy(copy, str, len); 601.1Scherry } 611.1Scherry return (copy); 621.1Scherry} 63