1 /* @(#)strdup.c 1.6 10/08/21 Copyright 2003-2010 J. Schilling */ 2 #include <schily/mconfig.h> 3 #ifndef lint 4 static UConst char sccsid[] = 5 "@(#)strdup.c 1.6 10/08/21 Copyright 2003-2010 J. Schilling"; 6 #endif 7 /* 8 * strdup() to be used if missing in libc 9 * 10 * Copyright (c) 2003-2010 J. Schilling 11 */ 12 /* 13 * The contents of this file are subject to the terms of the 14 * Common Development and Distribution License, Version 1.0 only 15 * (the "License"). You may not use this file except in compliance 16 * with the License. 17 * 18 * See the file CDDL.Schily.txt in this distribution for details. 19 * A copy of the CDDL is also available via the Internet at 20 * http://www.opensource.org/licenses/cddl1.txt 21 * 22 * When distributing Covered Code, include this CDDL HEADER in each 23 * file and include the License file CDDL.Schily.txt from this distribution. 24 */ 25 26 #include <schily/standard.h> 27 #include <schily/stdlib.h> 28 #include <schily/string.h> 29 #include <schily/unistd.h> 30 #include <schily/schily.h> 31 #include <schily/libport.h> 32 33 #ifndef HAVE_STRDUP 34 35 EXPORT char * strdup(s)36strdup(s) 37 const char *s; 38 { 39 unsigned i = strlen(s) + 1; 40 char *res = malloc(i); 41 42 if (res == NULL) 43 return (NULL); 44 if (i > 16) { 45 movebytes(s, res, (int)i); 46 } else { 47 char *s2 = res; 48 49 while ((*s2++ = *s++) != '\0') 50 ; 51 } 52 return (res); 53 } 54 #endif /* HAVE_STRDUP */ 55