Browse Source

some repairs, add example to strdup(3) page

OPENBSD_2_6
aaron 25 years ago
parent
commit
6d2a02c0cd
7 changed files with 44 additions and 31 deletions
  1. +3
    -2
      src/lib/libc/string/strcat.3
  2. +4
    -4
      src/lib/libc/string/strcmp.3
  3. +7
    -7
      src/lib/libc/string/strcpy.3
  4. +16
    -4
      src/lib/libc/string/strdup.3
  5. +3
    -4
      src/lib/libc/string/strlen.3
  6. +8
    -4
      src/lib/libc/string/strsep.3
  7. +3
    -6
      src/lib/libc/string/strtok.3

+ 3
- 2
src/lib/libc/string/strcat.3 View File

@ -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 <string.h>


+ 4
- 4
src/lib/libc/string/strcmp.3 View File

@ -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 <string.h>
@ -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


+ 7
- 7
src/lib/libc/string/strcpy.3 View File

@ -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 <string.h>
@ -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];


+ 16
- 4
src/lib/libc/string/strdup.3 View File

@ -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 <string.h>
.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 ,


+ 3
- 4
src/lib/libc/string/strlen.3 View File

@ -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 <string.h>
.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


+ 8
- 4
src/lib/libc/string/strsep.3 View File

@ -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


+ 3
- 6
src/lib/libc/string/strtok.3 View File

@ -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 <string.h>
@ -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 .

Loading…
Cancel
Save