diff options
author | 1999-04-24 01:17:37 +0000 | |
---|---|---|
committer | 1999-04-24 01:17:37 +0000 | |
commit | b44d0493b10fa1abd02d7d39a6563c5b88a53916 (patch) | |
tree | b94a1681e8a76d53a2911c5c319f07dfc3b9d473 /lib/libc/string/strlcpy.c | |
parent | correct keycap.pcvt path (diff) | |
download | wireguard-openbsd-b44d0493b10fa1abd02d7d39a6563c5b88a53916.tar.xz wireguard-openbsd-b44d0493b10fa1abd02d7d39a6563c5b88a53916.zip |
simplified version that doesn't call strlen and that is simpler to convert to assembler (both for gcc and me)
Diffstat (limited to 'lib/libc/string/strlcpy.c')
-rw-r--r-- | lib/libc/string/strlcpy.c | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/lib/libc/string/strlcpy.c b/lib/libc/string/strlcpy.c index 2b6a166175c..087f7c08838 100644 --- a/lib/libc/string/strlcpy.c +++ b/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 <Todd.Miller@courtesan.com> @@ -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 <sys/types.h> @@ -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 */ } |