1 /* @(#)strlcpy.c 1.4 09/07/08 Copyright 2006-2009 J. Schilling */ 2 #include <schily/mconfig.h> 3 #ifndef lint 4 static UConst char sccsid[] = 5 "@(#)strlcpy.c 1.4 09/07/08 Copyright 2006-2009 J. Schilling"; 6 #endif 7 /* 8 * strlcpy() to be used if missing in libc 9 * 10 * Copyright (c) 2006-2009 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/unistd.h> 28 #include <schily/libport.h> 29 30 #ifndef HAVE_STRLCPY 31 32 EXPORT size_t strlcpy(s1,s2,len)33strlcpy(s1, s2, len) 34 register char *s1; 35 register const char *s2; 36 register size_t len; 37 { 38 const char *os2 = s2; 39 40 if (len > 0) { 41 while (--len > 0 && (*s1++ = *s2++) != '\0') 42 ; 43 if (len == 0) { 44 *s1 = '\0'; 45 while (*s2++ != '\0') 46 ; 47 } 48 } else { 49 while (*s2++ != '\0') 50 ; 51 } 52 return (--s2 - os2); 53 } 54 #endif /* HAVE_STRLCPY */ 55