Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/lib/libc/string sync with latest openbsd.



details:   https://anonhg.NetBSD.org/src/rev/f5ebef9dbd3f
branches:  trunk
changeset: 499609:f5ebef9dbd3f
user:      itojun <itojun%NetBSD.org@localhost>
date:      Fri Nov 24 16:19:05 2000 +0000

description:
sync with latest openbsd.
comment in strlcat(3) was wrong about return value.

diffstat:

 lib/libc/string/strlcat.c |   9 +++++----
 lib/libc/string/strlcpy.3 |  44 +++++++++++++++++++++++++++++++++-----------
 2 files changed, 38 insertions(+), 15 deletions(-)

diffs (126 lines):

diff -r f0c881e5d5f8 -r f5ebef9dbd3f lib/libc/string/strlcat.c
--- a/lib/libc/string/strlcat.c Fri Nov 24 15:47:15 2000 +0000
+++ b/lib/libc/string/strlcat.c Fri Nov 24 16:19:05 2000 +0000
@@ -1,5 +1,5 @@
-/*     $NetBSD: strlcat.c,v 1.5 1999/09/20 04:39:47 lukem Exp $        */
-/*     from OpenBSD: strlcat.c,v 1.2 1999/06/17 16:28:58 millert Exp   */
+/*     $NetBSD: strlcat.c,v 1.6 2000/11/24 16:19:05 itojun Exp $       */
+/*     from OpenBSD: strlcat.c,v 1.3 2000/11/24 11:10:02 itojun Exp    */
 
 /*
  * Copyright (c) 1998 Todd C. Miller <Todd.Miller%courtesan.com@localhost>
@@ -30,7 +30,7 @@
 
 #include <sys/cdefs.h>
 #if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: strlcat.c,v 1.5 1999/09/20 04:39:47 lukem Exp $");
+__RCSID("$NetBSD: strlcat.c,v 1.6 2000/11/24 16:19:05 itojun Exp $");
 #endif /* LIBC_SCCS and not lint */
 
 #include <sys/types.h>
@@ -41,7 +41,8 @@
  * Appends src to string dst of size siz (unlike strncat, siz is the
  * full size of dst, not space left).  At most siz-1 characters
  * will be copied.  Always NUL terminates (unless siz == 0).
- * Returns strlen(src); if retval >= siz, truncation occurred.
+ * Returns strlen(initial dst) + strlen(src); if retval >= siz,
+ * truncation occurred.
  */
 size_t
 strlcat(dst, src, siz)
diff -r f0c881e5d5f8 -r f5ebef9dbd3f lib/libc/string/strlcpy.3
--- a/lib/libc/string/strlcpy.3 Fri Nov 24 15:47:15 2000 +0000
+++ b/lib/libc/string/strlcpy.3 Fri Nov 24 16:19:05 2000 +0000
@@ -1,7 +1,7 @@
-.\"    $NetBSD: strlcpy.3,v 1.2 1999/09/08 22:56:56 lukem Exp $
-.\" from OpenBSD: strlcpy.3,v 1.6 1999/09/04 02:22:46 pjanzen Exp 
+.\"    $NetBSD: strlcpy.3,v 1.3 2000/11/24 16:19:05 itojun Exp $
+.\" from OpenBSD: strlcpy.3,v 1.11 2000/11/16 23:27:41 angelos Exp
 .\"
-.\" Copyright (c) 1998 Todd C. Miller <Todd.Miller%courtesan.com@localhost>
+.\" Copyright (c) 1998, 2000 Todd C. Miller <Todd.Miller%courtesan.com@localhost>
 .\" All rights reserved.
 .\"
 .\" Redistribution and use in source and binary forms, with or without
@@ -26,7 +26,7 @@
 .\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
 .\" ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 .\"
-.Dd September 9, 1999
+.Dd June 22, 1998
 .Dt STRLCPY 3
 .Os
 .Sh NAME
@@ -44,7 +44,8 @@
 .Fn strlcpy
 and
 .Fn strlcat
-functions copy and concatenate strings respectively.  They are designed
+functions copy and concatenate strings respectively.
+They are designed
 to be safer, more consistent, and less error prone replacements for
 .Xr strncpy 3
 and
@@ -56,8 +57,29 @@
 take the full size of the buffer (not just the length) and guarantee to
 NUL-terminate the result (as long as
 .Fa size
-is larger than 0).  Note that you should include a byte for the NUL in
+is larger than 0 or, in the case of
+.Fn strlcat ,
+as long as there is at least one byte free in
+.Fa dst ) .
+Note that you should include a byte for the NUL in
 .Fa size .
+Also note that
+.Fn strlcpy  
+and
+.Fn strlcat
+only operate on true
+.Dq C
+strings.
+This means that for
+.Fn strlcpy
+.Fa src
+must be NUL-terminated and for
+.Fn strlcat
+both
+.Fa src
+and
+.Fa dst
+must be NUL-terminated.
 .Pp
 The
 .Fn strlcpy
@@ -83,8 +105,8 @@
 .Fn strlcpy
 and
 .Fn strlcat
-functions return the total length of the string they tried to
-create.  For
+functions return the total length of the string they tried to create.
+For
 .Fn strlcpy
 that means the length of
 .Fa src .
@@ -111,7 +133,7 @@
 To detect truncation, perhaps while building a pathname, something
 like the following might be used:
 .Bd -literal -offset indent
-char *dir, *file, pname[MAXPATHNAMELEN];
+char *dir, *file, pname[MAXPATHLEN];
 
 \&...
 
@@ -122,9 +144,9 @@
 .Ed
 .Pp
 Since we know how many characters we copied the first time, we can
-speed things up a bit by using a copy instead on an append:
+speed things up a bit by using a copy instead of an append:
 .Bd -literal -offset indent
-char *dir, *file, pname[MAXPATHNAMELEN];
+char *dir, *file, pname[MAXPATHLEN];
 size_t n;
 
 \&...



Home | Main Index | Thread Index | Old Index