diff --git a/src/lib/libc/string/strlcpy.c b/src/lib/libc/string/strlcpy.c index 2b6a1661..087f7c08 100644 --- a/src/lib/libc/string/strlcpy.c +++ b/src/lib/libc/string/strlcpy.c @@ -1,4 +1,4 @@ -/* $OpenBSD: strlcpy.c,v 1.2 1998/11/06 04:33:16 wvdputte Exp $ */ +/* $OpenBSD: strlcpy.c,v 1.3 1999/04/24 01:17:37 millert Exp $ */ /* * Copyright (c) 1998 Todd C. Miller @@ -28,7 +28,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char *rcsid = "$OpenBSD: strlcpy.c,v 1.2 1998/11/06 04:33:16 wvdputte Exp $"; +static char *rcsid = "$OpenBSD: strlcpy.c,v 1.3 1999/04/24 01:17:37 millert Exp $"; #endif /* LIBC_SCCS and not lint */ #include @@ -48,16 +48,17 @@ size_t strlcpy(dst, src, siz) register const char *s = src; register size_t n = siz; - if (n == 0) - return(strlen(s)); - while (*s != '\0') { - if (n != 1) { + if (n) + n--; /* don't count the NUL */ + while (*s) { + if (n) { *d++ = *s; n--; } s++; } - *d = '\0'; + if (siz) + *d = '\0'; return(s - src); /* count does not include NUL */ }