Browse Source

simplified version that doesn't call strlen and that is simpler to convert to assembler (both for gcc and me)

OPENBSD_2_6
millert 25 years ago
parent
commit
6412bd34bc
1 changed files with 8 additions and 7 deletions
  1. +8
    -7
      src/lib/libc/string/strlcpy.c

+ 8
- 7
src/lib/libc/string/strlcpy.c View File

@ -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 */
}

Loading…
Cancel
Save