diff options
Diffstat (limited to 'src/lib/libc')
| -rw-r--r-- | src/lib/libc/string/strlcpy.c | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/src/lib/libc/string/strlcpy.c b/src/lib/libc/string/strlcpy.c index 2b6a166175..087f7c0883 100644 --- a/src/lib/libc/string/strlcpy.c +++ b/src/lib/libc/string/strlcpy.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: strlcpy.c,v 1.2 1998/11/06 04:33:16 wvdputte Exp $ */ | 1 | /* $OpenBSD: strlcpy.c,v 1.3 1999/04/24 01:17:37 millert Exp $ */ |
| 2 | 2 | ||
| 3 | /* | 3 | /* |
| 4 | * Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com> | 4 | * Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com> |
| @@ -28,7 +28,7 @@ | |||
| 28 | */ | 28 | */ |
| 29 | 29 | ||
| 30 | #if defined(LIBC_SCCS) && !defined(lint) | 30 | #if defined(LIBC_SCCS) && !defined(lint) |
| 31 | static char *rcsid = "$OpenBSD: strlcpy.c,v 1.2 1998/11/06 04:33:16 wvdputte Exp $"; | 31 | static char *rcsid = "$OpenBSD: strlcpy.c,v 1.3 1999/04/24 01:17:37 millert Exp $"; |
| 32 | #endif /* LIBC_SCCS and not lint */ | 32 | #endif /* LIBC_SCCS and not lint */ |
| 33 | 33 | ||
| 34 | #include <sys/types.h> | 34 | #include <sys/types.h> |
| @@ -48,16 +48,17 @@ size_t strlcpy(dst, src, siz) | |||
| 48 | register const char *s = src; | 48 | register const char *s = src; |
| 49 | register size_t n = siz; | 49 | register size_t n = siz; |
| 50 | 50 | ||
| 51 | if (n == 0) | 51 | if (n) |
| 52 | return(strlen(s)); | 52 | n--; /* don't count the NUL */ |
| 53 | while (*s != '\0') { | 53 | while (*s) { |
| 54 | if (n != 1) { | 54 | if (n) { |
| 55 | *d++ = *s; | 55 | *d++ = *s; |
| 56 | n--; | 56 | n--; |
| 57 | } | 57 | } |
| 58 | s++; | 58 | s++; |
| 59 | } | 59 | } |
| 60 | *d = '\0'; | 60 | if (siz) |
| 61 | *d = '\0'; | ||
| 61 | 62 | ||
| 62 | return(s - src); /* count does not include NUL */ | 63 | return(s - src); /* count does not include NUL */ |
| 63 | } | 64 | } |
