shithub: purgatorio

ref: a5cb451b299b03f44154fac5780b6a57ca130ce0
dir: /man/10/strcat/

View raw version
.TH STRCAT 10.2
.SH NAME
strcat, strcmp, strncmp, strcpy, strncpy, strlen, strchr, strrchr, strdup, strstr \- string operations
.SH SYNOPSIS
.ta \w'\fLchar* \fP'u
.B
char*	strcat(char *s1, char *s2)
.PP
.B
int	strcmp(char *s1, char *s2)
.PP
.B
int	strncmp(char *s1, char *s2, long n)
.PP
.B
char*	strcpy(char *s1, char *s2)
.PP
.B
char*	strncpy(char *s1, char *s2, long n)
.PP
.B
long	strlen(char *s)
.PP
.B
char*	strchr(char *s, char c)
.PP
.B
char*	strrchr(char *s, char c)
.PP
.B
char*	strdup(char *s)
.PP
.B
char*	strstr(char *s1, char *s2)
.SH DESCRIPTION
The arguments
.I s1, s2
and
.I s
point to null-terminated strings.
The functions
.IR strcat ,
.IR strcpy ,
and
.I strncpy
all alter
.IR s1 .
These functions do not check for overflow of
the array pointed to by
.IR s1 .
.PP
.I Strcat
appends a copy of string
.I s2
to the end of string
.IR s1 ,
and
returns a pointer to the null-terminated result.
.PP
.I Strcmp
compares its arguments and returns an integer
less than, equal to, or greater than 0,
according as
.I s1
is lexicographically less than, equal to, or
greater than
.IR s2 .
.I Strncmp
makes the same comparison but examines at most
.I n
bytes.
The comparisons are made with unsigned bytes.
.PP
.I Strcpy
copies string
.I s2
to
.IR s1 ,
stopping after the null byte has been copied.
.I Strncpy
copies exactly
.I n
bytes,
truncating
.I s2
or adding
null bytes to
.I s1
if necessary.
The result will not be null-terminated if the length
of
.I s2
is
.I n
or more.
Each function returns
.IR s1 .
.PP
.I Strlen
returns the number of bytes in
.IR s ,
not including the terminating null byte.
.PP
.I Strchr
.RI ( strrchr )
returns a pointer to the first (last)
occurrence of byte
.I c
in string
.IR s ,
or
.L 0
if
.I c
does not occur in the string.
The null byte terminating a string is considered to
be part of the string.
.PP
.I Strdup
returns a pointer to a distinct copy of the null-terminated string
.I s
in space obtained from
.IR malloc (10.2)
or
.L 0
if no space can be obtained.
.PP
.I Strstr
returns a pointer to the first occurrence of
.I s2
as a substring of
.IR s1 ,
or 0 if there is none.
If
.I s2
is the null string,
.I strstr
returns
.IR s1 .
.SH SOURCE
.B /libkern/str*.c
.br
.B /libkern/str*-\fIobjtype\fP.c
.br
.B /lib9/strdup.c
.SH SEE ALSO
.IR memory (10.2),
.IR rune (10.2)
.SH BUGS
These routines know nothing about
.SM UTF.
Use the routines in
.IR rune (10.2)
as appropriate.
Note, however, that the definition of UTF guarantees that
.I strcmp
compares UTF strings correctly.
.PP
The outcome of overlapping moves varies among implementations.
.PP
Note the absence of ANSI C's
.IR strncat ,
.IR strpbrk ,
.IR strspn ,
.IR strcspn
and
.IR strtok ,
but the presence of
.IR strdup .
...strtod.c strtol.c strtoul.c strtoll.c