diff options
| author | millert <> | 2013-12-19 20:52:37 +0000 |
|---|---|---|
| committer | millert <> | 2013-12-19 20:52:37 +0000 |
| commit | 8d92c5014d1149b8e12f587c56f1843e30f42cff (patch) | |
| tree | ef71f36904bc7ca141dbe9cf9a9504e688b183c3 /src/lib/libc/string/strcat.3 | |
| parent | 9944b4747b70169a21b50d6ddc94f6b91cec7c2a (diff) | |
| download | openbsd-8d92c5014d1149b8e12f587c56f1843e30f42cff.tar.gz openbsd-8d92c5014d1149b8e12f587c56f1843e30f42cff.tar.bz2 openbsd-8d92c5014d1149b8e12f587c56f1843e30f42cff.zip | |
Split out strncpy and strncat from strcpy and strcat manuals.
Requested by deraadt@
Diffstat (limited to 'src/lib/libc/string/strcat.3')
| -rw-r--r-- | src/lib/libc/string/strcat.3 | 80 |
1 files changed, 9 insertions, 71 deletions
diff --git a/src/lib/libc/string/strcat.3 b/src/lib/libc/string/strcat.3 index 6b5e4003b6..fba992edd9 100644 --- a/src/lib/libc/string/strcat.3 +++ b/src/lib/libc/string/strcat.3 | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | .\" $OpenBSD: strcat.3,v 1.15 2013/07/17 05:42:11 schwarze Exp $ | 1 | .\" $OpenBSD: strcat.3,v 1.16 2013/12/19 20:52:37 millert Exp $ |
| 2 | .\" | 2 | .\" |
| 3 | .\" Copyright (c) 1990, 1991 The Regents of the University of California. | 3 | .\" Copyright (c) 1990, 1991 The Regents of the University of California. |
| 4 | .\" All rights reserved. | 4 | .\" All rights reserved. |
| @@ -31,91 +31,33 @@ | |||
| 31 | .\" 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 |
| 32 | .\" SUCH DAMAGE. | 32 | .\" SUCH DAMAGE. |
| 33 | .\" | 33 | .\" |
| 34 | .Dd $Mdocdate: July 17 2013 $ | 34 | .Dd $Mdocdate: December 19 2013 $ |
| 35 | .Dt STRCAT 3 | 35 | .Dt STRCAT 3 |
| 36 | .Os | 36 | .Os |
| 37 | .Sh NAME | 37 | .Sh NAME |
| 38 | .Nm strcat , | 38 | .Nm strcat |
| 39 | .Nm strncat | 39 | .Nd concatenate two strings |
| 40 | .Nd concatenate strings | ||
| 41 | .Sh SYNOPSIS | 40 | .Sh SYNOPSIS |
| 42 | .In string.h | 41 | .In string.h |
| 43 | .Ft char * | 42 | .Ft char * |
| 44 | .Fn strcat "char *s" "const char *append" | 43 | .Fn strcat "char *s" "const char *append" |
| 45 | .Ft char * | ||
| 46 | .Fn strncat "char *s" "const char *append" "size_t count" | ||
| 47 | .Sh DESCRIPTION | 44 | .Sh DESCRIPTION |
| 48 | The | 45 | The |
| 49 | .Fn strcat | 46 | .Fn strcat |
| 50 | and | 47 | function appends a copy of the NUL-terminated string |
| 51 | .Fn strncat | ||
| 52 | functions append a copy of the NUL-terminated string | ||
| 53 | .Fa append | 48 | .Fa append |
| 54 | to the end of the NUL-terminated string | 49 | to the end of the NUL-terminated string |
| 55 | .Fa s , | 50 | .Fa s , |
| 56 | then add a terminating | 51 | then adds a terminating |
| 57 | .Ql \e0 . | 52 | .Ql \e0 . |
| 58 | The string | 53 | The string |
| 59 | .Fa s | 54 | .Fa s |
| 60 | must have sufficient space to hold the result. | 55 | 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 | 56 | .Sh RETURN VALUES |
| 71 | The | 57 | The |
| 72 | .Fn strcat | 58 | .Fn strcat |
| 73 | and | 59 | function return the pointer |
| 74 | .Fn strncat | ||
| 75 | functions return the pointer | ||
| 76 | .Fa s . | 60 | .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 | 61 | .Sh SEE ALSO |
| 120 | .Xr bcopy 3 , | 62 | .Xr bcopy 3 , |
| 121 | .Xr memccpy 3 , | 63 | .Xr memccpy 3 , |
| @@ -123,21 +65,17 @@ functions are a better choice, as shown below. | |||
| 123 | .Xr memmove 3 , | 65 | .Xr memmove 3 , |
| 124 | .Xr strcpy 3 , | 66 | .Xr strcpy 3 , |
| 125 | .Xr strlcpy 3 , | 67 | .Xr strlcpy 3 , |
| 68 | .Xr strncat 3 , | ||
| 126 | .Xr wcscat 3 , | 69 | .Xr wcscat 3 , |
| 127 | .Xr wcslcpy 3 | 70 | .Xr wcslcpy 3 |
| 128 | .Sh STANDARDS | 71 | .Sh STANDARDS |
| 129 | The | 72 | The |
| 130 | .Fn strcat | 73 | .Fn strcat |
| 131 | and | 74 | function conforms to |
| 132 | .Fn strncat | ||
| 133 | functions conform to | ||
| 134 | .St -ansiC . | 75 | .St -ansiC . |
| 135 | .Sh HISTORY | 76 | .Sh HISTORY |
| 136 | The | 77 | The |
| 137 | .Fn strcat | 78 | .Fn strcat |
| 138 | function first appeared in the Programmer's Workbench (PWB/UNIX) | 79 | function first appeared in the Programmer's Workbench (PWB/UNIX) |
| 139 | and was ported to | 80 | and was ported to |
| 140 | .At v7 ; | ||
| 141 | .Fn strncat | ||
| 142 | first appeared in | ||
| 143 | .At v7 . | 81 | .At v7 . |
