From 6d2a02c0cd556b5f2a796fd5cf410bb6ed3c00d2 Mon Sep 17 00:00:00 2001 From: aaron <> Date: Fri, 4 Jun 1999 19:14:56 +0000 Subject: [PATCH] some repairs, add example to strdup(3) page --- src/lib/libc/string/strcat.3 | 5 +++-- src/lib/libc/string/strcmp.3 | 8 ++++---- src/lib/libc/string/strcpy.3 | 14 +++++++------- src/lib/libc/string/strdup.3 | 20 ++++++++++++++++---- src/lib/libc/string/strlen.3 | 7 +++---- src/lib/libc/string/strsep.3 | 12 ++++++++---- src/lib/libc/string/strtok.3 | 9 +++------ 7 files changed, 44 insertions(+), 31 deletions(-) diff --git a/src/lib/libc/string/strcat.3 b/src/lib/libc/string/strcat.3 index 7591423f..8b81e082 100644 --- a/src/lib/libc/string/strcat.3 +++ b/src/lib/libc/string/strcat.3 @@ -33,13 +33,14 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" $OpenBSD: strcat.3,v 1.5 1999/03/06 23:41:13 millert Exp $ +.\" $OpenBSD: strcat.3,v 1.6 1999/06/04 19:14:55 aaron Exp $ .\" .Dd July 8, 1997 .Dt STRCAT 3 .Os .Sh NAME -.Nm strcat +.Nm strcat, +.Nm strncat .Nd concatenate strings .Sh SYNOPSIS .Fd #include diff --git a/src/lib/libc/string/strcmp.3 b/src/lib/libc/string/strcmp.3 index 91e51d68..b8dc8ac4 100644 --- a/src/lib/libc/string/strcmp.3 +++ b/src/lib/libc/string/strcmp.3 @@ -33,13 +33,14 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" $OpenBSD: strcmp.3,v 1.2 1996/08/19 08:34:11 tholo Exp $ +.\" $OpenBSD: strcmp.3,v 1.3 1999/06/04 19:14:56 aaron Exp $ .\" .Dd June 29, 1991 .Dt STRCMP 3 .Os .Sh NAME -.Nm strcmp +.Nm strcmp, +.Nm strncmp .Nd compare strings .Sh SYNOPSIS .Fd #include @@ -72,9 +73,8 @@ The comparison is done using unsigned characters, so that is greater than .Ql \e0 . .Pp -The .Fn strncmp -compares not more than +compares at most .Fa len characters. .Sh SEE ALSO diff --git a/src/lib/libc/string/strcpy.3 b/src/lib/libc/string/strcpy.3 index 80d528ca..75727223 100644 --- a/src/lib/libc/string/strcpy.3 +++ b/src/lib/libc/string/strcpy.3 @@ -33,13 +33,14 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" $OpenBSD: strcpy.3,v 1.6 1999/05/23 14:11:03 aaron Exp $ +.\" $OpenBSD: strcpy.3,v 1.7 1999/06/04 19:14:56 aaron Exp $ .\" .Dd June 29, 1991 .Dt STRCPY 3 .Os .Sh NAME -.Nm strcpy +.Nm strcpy, +.Nm strncpy .Nd copy strings .Sh SYNOPSIS .Fd #include @@ -61,7 +62,6 @@ to .Ql \e0 character). .Pp -The .Fn strncpy copies not more than .Fa len @@ -105,10 +105,10 @@ to .Dq Li abcdef and does .Em not -NUL-terminate chararray because the source string is >= the length parameter. +null terminate chararray because the source string is >= the length parameter. .Fn strncpy .Em only -NUL-terminates the destination string when then length of the source +null terminates the destination string when then length of the source string is less than the length parameter. .Bd -literal -offset indent (void)strncpy(chararray, "abcdefgh", 6); @@ -118,11 +118,11 @@ The following copies as many characters from .Dq Li input to .Dq Li buf -as will fit and NUL-terminates the result. Because +as will fit and null terminates the result. Because .Fn strncpy does .Em not -guarantee to NUL-terminate the string itself, we must do this by hand. +guarantee to null terminate the string itself, we must do this by hand. .Bd -literal -offset indent char buf[BUFSIZ]; diff --git a/src/lib/libc/string/strdup.3 b/src/lib/libc/string/strdup.3 index 6abbba57..73c144d6 100644 --- a/src/lib/libc/string/strdup.3 +++ b/src/lib/libc/string/strdup.3 @@ -1,4 +1,4 @@ -.\" $OpenBSD: strdup.3,v 1.6 1998/08/19 05:51:14 pjanzen Exp $ +.\" $OpenBSD: strdup.3,v 1.7 1999/06/04 19:14:56 aaron Exp $ .\" .\" Copyright (c) 1990, 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -42,20 +42,32 @@ .Sh SYNOPSIS .Fd #include .Ft char * -.Fn strdup "const char *str" +.Fn strdup "const char *s" .Sh DESCRIPTION The .Fn strdup function allocates sufficient memory for a copy of the string -.Fa str , +.Fa s , does the copy, and returns a pointer to it. The pointer may subsequently be used as an argument to the function .Xr free 3 . .Pp -If insufficient memory is available, NULL is returned. +If insufficient memory is available, +.Dv NULL +is returned. +.Sh EXAMPLES +The following will point +.Va p +to an allocated area of memory containing the null-terminated string +.Qq foobar : +.Bd -literal -offset indent +char *p; + +p = strdup("foobar"); +.Ed .Sh SEE ALSO .Xr free 3 , .Xr malloc 3 , diff --git a/src/lib/libc/string/strlen.3 b/src/lib/libc/string/strlen.3 index 99e7dd19..9db28cd1 100644 --- a/src/lib/libc/string/strlen.3 +++ b/src/lib/libc/string/strlen.3 @@ -33,14 +33,14 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" $OpenBSD: strlen.3,v 1.2 1996/08/19 08:34:19 tholo Exp $ +.\" $OpenBSD: strlen.3,v 1.3 1999/06/04 19:14:56 aaron Exp $ .\" .Dd June 29, 1991 .Dt STRLEN 3 .Os .Sh NAME .Nm strlen -.Nd find length of string +.Nd find length of a string .Sh SYNOPSIS .Fd #include .Ft size_t @@ -57,8 +57,7 @@ The function returns the number of characters that precede the -terminating -.Dv NUL +terminating NUL character. .Sh SEE ALSO .Xr string 3 diff --git a/src/lib/libc/string/strsep.3 b/src/lib/libc/string/strsep.3 index 5af262a0..dfd835bc 100644 --- a/src/lib/libc/string/strsep.3 +++ b/src/lib/libc/string/strsep.3 @@ -1,4 +1,4 @@ -.\" $OpenBSD: strsep.3,v 1.4 1998/06/15 17:55:14 mickey Exp $ +.\" $OpenBSD: strsep.3,v 1.5 1999/06/04 19:14:56 aaron Exp $ .\" .\" Copyright (c) 1990, 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -58,13 +58,17 @@ the first occurrence of any character in the string character) and replaces it with a .Ql \e0 . The location of the next character after the delimiter character -(or NULL, if the end of the string was reached) is stored in +(or +.Dv NULL , +if the end of the string was reached) is stored in .Fa *stringp . The original value of .Fa *stringp is returned. .Pp -An ``empty'' field, i.e. one caused by two adjacent delimiter characters, +An +.Dq empty +field, i.e., one caused by two adjacent delimiter characters, can be detected by comparing the location referenced by the pointer returned in .Fa *stringp @@ -101,7 +105,7 @@ While the .Fn strtok function should be preferred for portability reasons (it conforms to .St -ansiC ) -it is unable to handle empty fields, i.e. detect fields delimited by +it is unable to handle empty fields, i.e., detect fields delimited by two adjacent delimiter characters, or to be used for more than a single string at a time. The diff --git a/src/lib/libc/string/strtok.3 b/src/lib/libc/string/strtok.3 index 6abcfc67..62f0d7a5 100644 --- a/src/lib/libc/string/strtok.3 +++ b/src/lib/libc/string/strtok.3 @@ -33,14 +33,13 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" $OpenBSD: strtok.3,v 1.4 1999/05/23 14:11:03 aaron Exp $ +.\" $OpenBSD: strtok.3,v 1.5 1999/06/04 19:14:56 aaron Exp $ .\" .Dd June 29, 1991 .Dt STRTOK 3 .Os .Sh NAME -.Nm strtok , -.Nm strsep +.Nm strtok .Nd string token operations .Sh SYNOPSIS .Fd #include @@ -104,9 +103,7 @@ if handed a string containing only delimiter characters, will not alter the next starting point, so that a call to .Fn strtok with a different (or empty) delimiter string -may return a -.Pf non- Dv NULL -value. +may return a non-null value. Since this implementation always alters the next starting point, such a sequence of calls would always return .Dv NULL .