diff options
Diffstat (limited to 'src/lib/libc/string/strcat.3')
| -rw-r--r-- | src/lib/libc/string/strcat.3 | 75 |
1 files changed, 56 insertions, 19 deletions
diff --git a/src/lib/libc/string/strcat.3 b/src/lib/libc/string/strcat.3 index 5357d65754..5b878c3e8c 100644 --- a/src/lib/libc/string/strcat.3 +++ b/src/lib/libc/string/strcat.3 | |||
| @@ -13,11 +13,7 @@ | |||
| 13 | .\" 2. Redistributions in binary form must reproduce the above copyright | 13 | .\" 2. Redistributions in binary form must reproduce the above copyright |
| 14 | .\" notice, this list of conditions and the following disclaimer in the | 14 | .\" notice, this list of conditions and the following disclaimer in the |
| 15 | .\" documentation and/or other materials provided with the distribution. | 15 | .\" documentation and/or other materials provided with the distribution. |
| 16 | .\" 3. All advertising materials mentioning features or use of this software | 16 | .\" 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 | 17 | .\" may be used to endorse or promote products derived from this software |
| 22 | .\" without specific prior written permission. | 18 | .\" without specific prior written permission. |
| 23 | .\" | 19 | .\" |
| @@ -33,14 +29,14 @@ | |||
| 33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 29 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 34 | .\" SUCH DAMAGE. | 30 | .\" SUCH DAMAGE. |
| 35 | .\" | 31 | .\" |
| 36 | .\" from: @(#)strcat.3 5.6 (Berkeley) 6/29/91 | 32 | .\" $OpenBSD: strcat.3,v 1.9 2003/06/02 20:18:38 millert Exp $ |
| 37 | .\" $Id: strcat.3,v 1.1.1.1 1995/10/18 08:42:22 deraadt Exp $ | ||
| 38 | .\" | 33 | .\" |
| 39 | .Dd June 29, 1991 | 34 | .Dd July 8, 1997 |
| 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,8 +49,7 @@ 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 null-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 null-terminated string |
| 60 | .Fa s , | 55 | .Fa s , |
| @@ -66,29 +61,71 @@ 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 | .Dq Li 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 | .Dq Li input | ||
| 103 | to | ||
| 104 | .Dq Li buf | ||
| 105 | as will fit. | ||
| 106 | It then appends as many characters from suffix as will fit (or none | ||
| 107 | if there is no space). | ||
| 108 | For operations like this, the | ||
| 109 | .Xr strlcpy 3 | ||
| 110 | and | ||
| 111 | .Xr strlcat 3 | ||
| 112 | functions are a better choice, as shown below. | ||
| 113 | .Bd -literal -offset indent | ||
| 114 | (void)strlcpy(buf, input, sizeof(buf)); | ||
| 115 | (void)strlcat(buf, suffix, sizeof(buf)); | ||
| 116 | .Ed | ||
| 81 | .Sh SEE ALSO | 117 | .Sh SEE ALSO |
| 82 | .Xr bcopy 3 , | 118 | .Xr bcopy 3 , |
| 83 | .Xr memccpy 3 , | 119 | .Xr memccpy 3 , |
| 84 | .Xr memcpy 3 , | 120 | .Xr memcpy 3 , |
| 85 | .Xr memmove 3 , | 121 | .Xr memmove 3 , |
| 86 | .Xr strcpy 3 | 122 | .Xr strcpy 3 , |
| 123 | .Xr strlcat 3 , | ||
| 124 | .Xr strlcpy 3 | ||
| 87 | .Sh STANDARDS | 125 | .Sh STANDARDS |
| 88 | The | 126 | The |
| 89 | .Fn strcat | 127 | .Fn strcat |
| 90 | and | 128 | and |
| 91 | .Fn strncat | 129 | .Fn strncat |
| 92 | functions | 130 | functions conform to |
| 93 | conform to | ||
| 94 | .St -ansiC . | 131 | .St -ansiC . |
