diff options
| author | millert <> | 1999-03-06 23:41:13 +0000 |
|---|---|---|
| committer | millert <> | 1999-03-06 23:41:13 +0000 |
| commit | 3aad6ac81b2ea32ef6e1be43fe2ce8985062ea5f (patch) | |
| tree | 8ad710f496593d4bab090cb087b9bbe77abf205f | |
| parent | 6fb16762fb409583f9e1850a83bc1f69bb2ce276 (diff) | |
| download | openbsd-3aad6ac81b2ea32ef6e1be43fe2ce8985062ea5f.tar.gz openbsd-3aad6ac81b2ea32ef6e1be43fe2ce8985062ea5f.tar.bz2 openbsd-3aad6ac81b2ea32ef6e1be43fe2ce8985062ea5f.zip | |
add examples
| -rw-r--r-- | src/lib/libc/string/strcat.3 | 41 |
1 files changed, 40 insertions, 1 deletions
diff --git a/src/lib/libc/string/strcat.3 b/src/lib/libc/string/strcat.3 index 3aa171ce88..7591423f96 100644 --- a/src/lib/libc/string/strcat.3 +++ b/src/lib/libc/string/strcat.3 | |||
| @@ -33,7 +33,7 @@ | |||
| 33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 34 | .\" SUCH DAMAGE. | 34 | .\" SUCH DAMAGE. |
| 35 | .\" | 35 | .\" |
| 36 | .\" $OpenBSD: strcat.3,v 1.4 1998/11/28 14:51:34 espie Exp $ | 36 | .\" $OpenBSD: strcat.3,v 1.5 1999/03/06 23:41:13 millert Exp $ |
| 37 | .\" | 37 | .\" |
| 38 | .Dd July 8, 1997 | 38 | .Dd July 8, 1997 |
| 39 | .Dt STRCAT 3 | 39 | .Dt STRCAT 3 |
| @@ -80,6 +80,45 @@ and | |||
| 80 | functions | 80 | functions |
| 81 | return the pointer | 81 | return the pointer |
| 82 | .Fa s . | 82 | .Fa s . |
| 83 | .Sh EXAMPLES | ||
| 84 | The following appends | ||
| 85 | .Dq Li abc | ||
| 86 | to | ||
| 87 | .Dq Li chararray : | ||
| 88 | .Bd -literal -offset indent | ||
| 89 | char *letters = "abcdefghi"; | ||
| 90 | |||
| 91 | (void)strncat(chararray, letters, 3); | ||
| 92 | .Ed | ||
| 93 | .Pp | ||
| 94 | The following example shows how to use | ||
| 95 | .Fn strncat | ||
| 96 | safely in conjunction with | ||
| 97 | .Xr strncpy 3 . | ||
| 98 | .Bd -literal -offset indent | ||
| 99 | char buf[BUFSIZ]; | ||
| 100 | char *input, *suffix; | ||
| 101 | |||
| 102 | (void)strncpy(buf, input, sizeof(buf) - 1); | ||
| 103 | buf[sizeof(buf) - 1] = '\e0'; | ||
| 104 | (void)strncat(buf, suffix, sizeof(buf) - 1 - strlen(buf)); | ||
| 105 | .Ed | ||
| 106 | .Pp | ||
| 107 | The above will copy as many characters from | ||
| 108 | .Dq Li input | ||
| 109 | to | ||
| 110 | .Dq Li buf | ||
| 111 | as will | ||
| 112 | fit. It then appends as many characters from suffix as will fit (or none | ||
| 113 | if there is no space). For operations like this, the | ||
| 114 | .Xr strlcpy 3 | ||
| 115 | and | ||
| 116 | .Xr strlcat 3 | ||
| 117 | functions are a better choice, as shown below. | ||
| 118 | .Bd -literal -offset indent | ||
| 119 | (void)strlcpy(buf, input, sizeof(buf)); | ||
| 120 | (void)strlcat(buf, suffix, sizeof(buf)); | ||
| 121 | .Ed | ||
| 83 | .Sh SEE ALSO | 122 | .Sh SEE ALSO |
| 84 | .Xr bcopy 3 , | 123 | .Xr bcopy 3 , |
| 85 | .Xr memccpy 3 , | 124 | .Xr memccpy 3 , |
