1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License, Version 1.0 only 6 * (the "License"). You may not use this file except in compliance 7 * with the License. 8 * 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 * or http://www.opensolaris.org/os/licensing. 11 * See the License for the specific language governing permissions 12 * and limitations under the License. 13 * 14 * When distributing Covered Code, include this CDDL HEADER in each 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 * If applicable, add the following below this CDDL HEADER, with the 17 * fields enclosed by brackets "[]" replaced with your own identifying 18 * information: Portions Copyright [yyyy] [name of copyright owner] 19 * 20 * CDDL HEADER END 21 */ 22 /* 23 * Copyright (c) 1996, by Sun Microsystems, Inc. 24 * All rights reserved. 25 */ 26 27 /* 28 * Copyright 1992 by Mortice Kern Systems Inc. All rights reserved. 29 * 30 */ 31 #ifdef M_RCSID 32 #ifndef lint 33 static char rcsID[] = "$Id: m_strdup.c 1.8 1993/05/28 07:43:26 scott Exp $"; 34 #endif 35 #endif 36 37 #include <mks.h> 38 #include <string.h> 39 #include <stdlib.h> 40 41 /*f 42 * Return a copy of the string `s', issue an error and return NULL. 43 */ 44 LDEFN char * 45 m_strdup(s) 46 const char *s; 47 { 48 char *cp; 49 int len; 50 51 if ((cp = m_malloc(len = strlen(s)+1)) == NULL) { 52 m_error(m_textmsg(3581, "!memory allocation failure", "E")); 53 return NULL; 54 } 55 return (memcpy(cp, s, len)); 56 } 57