manual page distributed with 4.1BSD
[unix-history] / usr / src / lib / libc / string / string.3
CommitLineData
2fe842cb
KM
1.\" Copyright (c) 1980 Regents of the University of California.
2.\" All rights reserved. The Berkeley software License Agreement
3.\" specifies the terms and conditions for redistribution.
4.\"
5.\" @(#)string.3 4.1 (Berkeley) %G%
6.\"
7.TH STRING 3
8.UC 4
9.SH NAME
10strcat, strncat, strcmp, strncmp, strcpy, strncpy, strlen, index, rindex \- string operations
11.SH SYNOPSIS
12.nf
13.B char *strcat(s1, s2)
14.B char *s1, *s2;
15.PP
16.B char *strncat(s1, s2, n)
17.B char *s1, *s2;
18.PP
19.B strcmp(s1, s2)
20.B char *s1, *s2;
21.PP
22.B strncmp(s1, s2, n)
23.B char *s1, *s2;
24.PP
25.B char *strcpy(s1, s2)
26.B char *s1, *s2;
27.PP
28.B char *strncpy(s1, s2, n)
29.B char *s1, *s2;
30.PP
31.B strlen(s)
32.B char *s;
33.PP
34.B char *index(s, c)
35.B char *s, c;
36.PP
37.B char *rindex(s, c)
38.B char *s, c;
39.fi
40.SH DESCRIPTION
41These functions operate on null-terminated strings.
42They do not check for overflow of any receiving string.
43.PP
44.I Strcat
45appends a copy of string
46.I s2
47to the end of string
48.IR s1 .
49.I Strncat
50copies at most
51.I n
52characters.
53Both return a pointer to the null-terminated result.
54.PP
55.I Strcmp
56compares its arguments and returns an integer
57greater than, equal to, or less than 0,
58according as
59.I s1
60is lexicographically greater than, equal to, or
61less than
62.IR s2 .
63.I Strncmp
64makes the same comparison but looks at at most
65.I n
66characters.
67.PP
68.I Strcpy
69copies string
70.I s2
71to
72.I s1,
73stopping after the null character has been moved.
74.I Strncpy
75copies exactly
76.I n
77characters,
78truncating or null-padding
79.I s2;
80the target may not be null-terminated if the length
81of
82.I s2
83is
84.I n
85or more.
86Both return
87.IR s1 .
88.PP
89.I Strlen
90returns the number of non-null characters in
91.IR s .
92.PP
93.I Index
94.RI ( rindex )
95returns a pointer to the first (last)
96occurrence of character
97.I c
98in string
99.I s,
100or zero if
101.I c
102does not occur in the string.
103.SH BUGS
104.I Strcmp
105uses native character comparison, which is signed
106on PDP11's and VAX-11's, unsigned on other machines.