diff options
Diffstat (limited to 'src/lib/libc/string/strncat.3')
-rw-r--r-- | src/lib/libc/string/strncat.3 | 128 |
1 files changed, 128 insertions, 0 deletions
diff --git a/src/lib/libc/string/strncat.3 b/src/lib/libc/string/strncat.3 new file mode 100644 index 0000000000..38eabe3474 --- /dev/null +++ b/src/lib/libc/string/strncat.3 | |||
@@ -0,0 +1,128 @@ | |||
1 | .\" $OpenBSD: strncat.3,v 1.1 2013/12/19 20:52:37 millert Exp $ | ||
2 | .\" | ||
3 | .\" Copyright (c) 1990, 1991 The Regents of the University of California. | ||
4 | .\" All rights reserved. | ||
5 | .\" | ||
6 | .\" This code is derived from software contributed to Berkeley by | ||
7 | .\" Chris Torek and the American National Standards Committee X3, | ||
8 | .\" on Information Processing Systems. | ||
9 | .\" | ||
10 | .\" Redistribution and use in source and binary forms, with or without | ||
11 | .\" modification, are permitted provided that the following conditions | ||
12 | .\" are met: | ||
13 | .\" 1. Redistributions of source code must retain the above copyright | ||
14 | .\" notice, this list of conditions and the following disclaimer. | ||
15 | .\" 2. Redistributions in binary form must reproduce the above copyright | ||
16 | .\" notice, this list of conditions and the following disclaimer in the | ||
17 | .\" documentation and/or other materials provided with the distribution. | ||
18 | .\" 3. Neither the name of the University nor the names of its contributors | ||
19 | .\" may be used to endorse or promote products derived from this software | ||
20 | .\" without specific prior written permission. | ||
21 | .\" | ||
22 | .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | ||
23 | .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
24 | .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
25 | .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | ||
26 | .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
27 | .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
28 | .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
29 | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
30 | .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
31 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
32 | .\" SUCH DAMAGE. | ||
33 | .\" | ||
34 | .Dd $Mdocdate: December 19 2013 $ | ||
35 | .Dt STRNCAT 3 | ||
36 | .Os | ||
37 | .Sh NAME | ||
38 | .Nm strncat | ||
39 | .Nd concatenate a string with part of another | ||
40 | .Sh SYNOPSIS | ||
41 | .In string.h | ||
42 | .Ft char * | ||
43 | .Fn strncat "char *s" "const char *append" "size_t count" | ||
44 | .Sh DESCRIPTION | ||
45 | The | ||
46 | .Fn strncat | ||
47 | function appends not more than | ||
48 | .Fa count | ||
49 | characters of the NUL-terminated string | ||
50 | .Fa append | ||
51 | to the end of the NUL-terminated string | ||
52 | .Fa s . | ||
53 | Space for the terminating | ||
54 | .Ql \e0 | ||
55 | should not be included in | ||
56 | .Fa count . | ||
57 | The string | ||
58 | .Fa s | ||
59 | must have sufficient space to hold the result. | ||
60 | .Sh RETURN VALUES | ||
61 | The | ||
62 | .Fn strncat | ||
63 | function returns the pointer | ||
64 | .Fa s . | ||
65 | .Sh EXAMPLES | ||
66 | The following appends | ||
67 | .Dq Li abc | ||
68 | to | ||
69 | .Va chararray : | ||
70 | .Bd -literal -offset indent | ||
71 | char *letters = "abcdefghi"; | ||
72 | |||
73 | (void)strncat(chararray, letters, 3); | ||
74 | .Ed | ||
75 | .Pp | ||
76 | The following example shows how to use | ||
77 | .Fn strncat | ||
78 | safely in conjunction with | ||
79 | .Xr strncpy 3 . | ||
80 | .Bd -literal -offset indent | ||
81 | char buf[BUFSIZ]; | ||
82 | char *input, *suffix; | ||
83 | |||
84 | (void)strncpy(buf, input, sizeof(buf) - 1); | ||
85 | buf[sizeof(buf) - 1] = '\e0'; | ||
86 | (void)strncat(buf, suffix, sizeof(buf) - 1 - strlen(buf)); | ||
87 | .Ed | ||
88 | .Pp | ||
89 | The above will copy as many characters from | ||
90 | .Va input | ||
91 | to | ||
92 | .Va buf | ||
93 | as will fit. | ||
94 | It then appends as many characters from | ||
95 | .Va suffix | ||
96 | as will fit (or none | ||
97 | if there is no space). | ||
98 | For operations like this, the | ||
99 | .Xr strlcpy 3 | ||
100 | and | ||
101 | .Xr strlcat 3 | ||
102 | functions are a better choice, as shown below. | ||
103 | .Bd -literal -offset indent | ||
104 | (void)strlcpy(buf, input, sizeof(buf)); | ||
105 | (void)strlcat(buf, suffix, sizeof(buf)); | ||
106 | .Ed | ||
107 | .Sh SEE ALSO | ||
108 | .Xr bcopy 3 , | ||
109 | .Xr memccpy 3 , | ||
110 | .Xr memcpy 3 , | ||
111 | .Xr memmove 3 , | ||
112 | .Xr strcat 3 , | ||
113 | .Xr strcpy 3 , | ||
114 | .Xr strlcpy 3 , | ||
115 | .Xr wcscat 3 , | ||
116 | .Xr wcslcpy 3 | ||
117 | .Sh STANDARDS | ||
118 | The | ||
119 | .Fn strcat | ||
120 | and | ||
121 | .Fn strncat | ||
122 | functions conform to | ||
123 | .St -ansiC . | ||
124 | .Sh HISTORY | ||
125 | The | ||
126 | .Fn strncat | ||
127 | function first first appeared in | ||
128 | .At v7 . | ||