summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormillert <>1999-03-06 23:41:13 +0000
committermillert <>1999-03-06 23:41:13 +0000
commit3aad6ac81b2ea32ef6e1be43fe2ce8985062ea5f (patch)
tree8ad710f496593d4bab090cb087b9bbe77abf205f
parent6fb16762fb409583f9e1850a83bc1f69bb2ce276 (diff)
downloadopenbsd-3aad6ac81b2ea32ef6e1be43fe2ce8985062ea5f.tar.gz
openbsd-3aad6ac81b2ea32ef6e1be43fe2ce8985062ea5f.tar.bz2
openbsd-3aad6ac81b2ea32ef6e1be43fe2ce8985062ea5f.zip
add examples
-rw-r--r--src/lib/libc/string/strcat.341
1 files changed, 40 insertions, 1 deletions
diff --git a/src/lib/libc/string/strcat.3 b/src/lib/libc/string/strcat.3
index 3aa171ce88..7591423f96 100644
--- a/src/lib/libc/string/strcat.3
+++ b/src/lib/libc/string/strcat.3
@@ -33,7 +33,7 @@
33.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34.\" SUCH DAMAGE. 34.\" SUCH DAMAGE.
35.\" 35.\"
36.\" $OpenBSD: strcat.3,v 1.4 1998/11/28 14:51:34 espie Exp $ 36.\" $OpenBSD: strcat.3,v 1.5 1999/03/06 23:41:13 millert Exp $
37.\" 37.\"
38.Dd July 8, 1997 38.Dd July 8, 1997
39.Dt STRCAT 3 39.Dt STRCAT 3
@@ -80,6 +80,45 @@ and
80functions 80functions
81return the pointer 81return the pointer
82.Fa s . 82.Fa s .
83.Sh EXAMPLES
84The following appends
85.Dq Li abc
86to
87.Dq Li chararray :
88.Bd -literal -offset indent
89char *letters = "abcdefghi";
90
91(void)strncat(chararray, letters, 3);
92.Ed
93.Pp
94The following example shows how to use
95.Fn strncat
96safely in conjunction with
97.Xr strncpy 3 .
98.Bd -literal -offset indent
99char buf[BUFSIZ];
100char *input, *suffix;
101
102(void)strncpy(buf, input, sizeof(buf) - 1);
103buf[sizeof(buf) - 1] = '\e0';
104(void)strncat(buf, suffix, sizeof(buf) - 1 - strlen(buf));
105.Ed
106.Pp
107The above will copy as many characters from
108.Dq Li input
109to
110.Dq Li buf
111as will
112fit. It then appends as many characters from suffix as will fit (or none
113if there is no space). For operations like this, the
114.Xr strlcpy 3
115and
116.Xr strlcat 3
117functions are a better choice, as shown below.
118.Bd -literal -offset indent
119(void)strlcpy(buf, input, sizeof(buf));
120(void)strlcat(buf, suffix, sizeof(buf));
121.Ed
83.Sh SEE ALSO 122.Sh SEE ALSO
84.Xr bcopy 3 , 123.Xr bcopy 3 ,
85.Xr memccpy 3 , 124.Xr memccpy 3 ,