diff options
Diffstat (limited to 'src/lib/libc/string/strcat.3')
| -rw-r--r-- | src/lib/libc/string/strcat.3 | 89 |
1 files changed, 68 insertions, 21 deletions
diff --git a/src/lib/libc/string/strcat.3 b/src/lib/libc/string/strcat.3 index 5357d65754..81aae19a63 100644 --- a/src/lib/libc/string/strcat.3 +++ b/src/lib/libc/string/strcat.3 | |||
| @@ -1,3 +1,5 @@ | |||
| 1 | .\" $OpenBSD: strcat.3,v 1.13 2011/07/25 00:38:52 schwarze Exp $ | ||
| 2 | .\" | ||
| 1 | .\" Copyright (c) 1990, 1991 The Regents of the University of California. | 3 | .\" Copyright (c) 1990, 1991 The Regents of the University of California. |
| 2 | .\" All rights reserved. | 4 | .\" All rights reserved. |
| 3 | .\" | 5 | .\" |
| @@ -13,11 +15,7 @@ | |||
| 13 | .\" 2. Redistributions in binary form must reproduce the above copyright | 15 | .\" 2. Redistributions in binary form must reproduce the above copyright |
| 14 | .\" notice, this list of conditions and the following disclaimer in the | 16 | .\" notice, this list of conditions and the following disclaimer in the |
| 15 | .\" documentation and/or other materials provided with the distribution. | 17 | .\" documentation and/or other materials provided with the distribution. |
| 16 | .\" 3. All advertising materials mentioning features or use of this software | 18 | .\" 3. Neither the name of the University nor the names of its contributors |
| 17 | .\" must display the following acknowledgement: | ||
| 18 | .\" This product includes software developed by the University of | ||
| 19 | .\" California, Berkeley and its contributors. | ||
| 20 | .\" 4. Neither the name of the University nor the names of its contributors | ||
| 21 | .\" may be used to endorse or promote products derived from this software | 19 | .\" may be used to endorse or promote products derived from this software |
| 22 | .\" without specific prior written permission. | 20 | .\" without specific prior written permission. |
| 23 | .\" | 21 | .\" |
| @@ -33,14 +31,12 @@ | |||
| 33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 31 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 34 | .\" SUCH DAMAGE. | 32 | .\" SUCH DAMAGE. |
| 35 | .\" | 33 | .\" |
| 36 | .\" from: @(#)strcat.3 5.6 (Berkeley) 6/29/91 | 34 | .Dd $Mdocdate: July 25 2011 $ |
| 37 | .\" $Id: strcat.3,v 1.1.1.1 1995/10/18 08:42:22 deraadt Exp $ | ||
| 38 | .\" | ||
| 39 | .Dd June 29, 1991 | ||
| 40 | .Dt STRCAT 3 | 35 | .Dt STRCAT 3 |
| 41 | .Os | 36 | .Os |
| 42 | .Sh NAME | 37 | .Sh NAME |
| 43 | .Nm strcat | 38 | .Nm strcat , |
| 39 | .Nm strncat | ||
| 44 | .Nd concatenate strings | 40 | .Nd concatenate strings |
| 45 | .Sh SYNOPSIS | 41 | .Sh SYNOPSIS |
| 46 | .Fd #include <string.h> | 42 | .Fd #include <string.h> |
| @@ -53,10 +49,9 @@ The | |||
| 53 | .Fn strcat | 49 | .Fn strcat |
| 54 | and | 50 | and |
| 55 | .Fn strncat | 51 | .Fn strncat |
| 56 | functions | 52 | functions append a copy of the NUL-terminated string |
| 57 | append a copy of the null-terminated string | ||
| 58 | .Fa append | 53 | .Fa append |
| 59 | to the end of the null-terminated string | 54 | to the end of the NUL-terminated string |
| 60 | .Fa s , | 55 | .Fa s , |
| 61 | then add a terminating | 56 | then add a terminating |
| 62 | .Ql \e0 . | 57 | .Ql \e0 . |
| @@ -66,29 +61,81 @@ must have sufficient space to hold the result. | |||
| 66 | .Pp | 61 | .Pp |
| 67 | The | 62 | The |
| 68 | .Fn strncat | 63 | .Fn strncat |
| 69 | function | 64 | function appends not more than |
| 70 | appends not more than | ||
| 71 | .Fa count | 65 | .Fa count |
| 72 | characters. | 66 | characters where space for the terminating |
| 67 | .Ql \e0 | ||
| 68 | should not be included in | ||
| 69 | .Fa count . | ||
| 73 | .Sh RETURN VALUES | 70 | .Sh RETURN VALUES |
| 74 | The | 71 | The |
| 75 | .Fn strcat | 72 | .Fn strcat |
| 76 | and | 73 | and |
| 77 | .Fn strncat | 74 | .Fn strncat |
| 78 | functions | 75 | functions return the pointer |
| 79 | return the pointer | ||
| 80 | .Fa s . | 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 | ||
| 81 | .Sh SEE ALSO | 119 | .Sh SEE ALSO |
| 82 | .Xr bcopy 3 , | 120 | .Xr bcopy 3 , |
| 83 | .Xr memccpy 3 , | 121 | .Xr memccpy 3 , |
| 84 | .Xr memcpy 3 , | 122 | .Xr memcpy 3 , |
| 85 | .Xr memmove 3 , | 123 | .Xr memmove 3 , |
| 86 | .Xr strcpy 3 | 124 | .Xr strcpy 3 , |
| 125 | .Xr strlcpy 3 , | ||
| 126 | .Xr wcscat 3 , | ||
| 127 | .Xr wcslcpy 3 | ||
| 87 | .Sh STANDARDS | 128 | .Sh STANDARDS |
| 88 | The | 129 | The |
| 89 | .Fn strcat | 130 | .Fn strcat |
| 90 | and | 131 | and |
| 91 | .Fn strncat | 132 | .Fn strncat |
| 92 | functions | 133 | functions conform to |
| 93 | conform to | ||
| 94 | .St -ansiC . | 134 | .St -ansiC . |
| 135 | .Sh HISTORY | ||
| 136 | The | ||
| 137 | .Fn strcat | ||
| 138 | and | ||
| 139 | .Fn strncat | ||
| 140 | functions first appeared in | ||
| 141 | .At v7 . | ||
