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