diff options
Diffstat (limited to 'src/lib/libc/string/wcslcpy.3')
| -rw-r--r-- | src/lib/libc/string/wcslcpy.3 | 139 |
1 files changed, 139 insertions, 0 deletions
diff --git a/src/lib/libc/string/wcslcpy.3 b/src/lib/libc/string/wcslcpy.3 new file mode 100644 index 0000000000..6f068dc9df --- /dev/null +++ b/src/lib/libc/string/wcslcpy.3 | |||
| @@ -0,0 +1,139 @@ | |||
| 1 | .\" $OpenBSD: wcslcpy.3,v 1.1 2011/07/09 16:32:11 nicm Exp $ | ||
| 2 | .\" | ||
| 3 | .\" Copyright (c) 1998, 2000 Todd C. Miller <Todd.Miller@courtesan.com> | ||
| 4 | .\" | ||
| 5 | .\" Permission to use, copy, modify, and distribute this software for any | ||
| 6 | .\" purpose with or without fee is hereby granted, provided that the above | ||
| 7 | .\" copyright notice and this permission notice appear in all copies. | ||
| 8 | .\" | ||
| 9 | .\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
| 10 | .\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
| 11 | .\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
| 12 | .\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
| 13 | .\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
| 14 | .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
| 15 | .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
| 16 | .\" | ||
| 17 | .Dd $Mdocdate: July 9 2011 $ | ||
| 18 | .Dt WCSLCPY 3 | ||
| 19 | .Os | ||
| 20 | .Sh NAME | ||
| 21 | .Nm wcslcpy , | ||
| 22 | .Nm wcslcat | ||
| 23 | .Nd size-bounded wide string copying and concatenation | ||
| 24 | .Sh SYNOPSIS | ||
| 25 | .Fd #include <wchar.h> | ||
| 26 | .Ft size_t | ||
| 27 | .Fn wcslcpy "wchar_t *dst" "const wchar_t *src" "size_t size" | ||
| 28 | .Ft size_t | ||
| 29 | .Fn wcslcat "wchar_t *dst" "const wchar_t *src" "size_t size" | ||
| 30 | .Sh DESCRIPTION | ||
| 31 | The | ||
| 32 | .Fn wcslcpy | ||
| 33 | and | ||
| 34 | .Fn wcslcat | ||
| 35 | functions copy and concatenate wide strings respectively. | ||
| 36 | They are designed to be safer, more consistent, and less error prone | ||
| 37 | replacements for | ||
| 38 | .Xr wcsncpy 3 | ||
| 39 | and | ||
| 40 | .Xr wcsncat 3 . | ||
| 41 | Unlike those functions, | ||
| 42 | .Fn wcslcpy | ||
| 43 | and | ||
| 44 | .Fn wcslcat | ||
| 45 | take the full size of the buffer (not just the length) and guarantee to | ||
| 46 | terminate the result with a null wide character (as long as | ||
| 47 | .Fa size | ||
| 48 | is larger than 0 or, in the case of | ||
| 49 | .Fn wcslcat , | ||
| 50 | as long as there is at least one wide character free in | ||
| 51 | .Fa dst ) . | ||
| 52 | Note that a wide character for the null wide character should be included in | ||
| 53 | .Fa size . | ||
| 54 | Also note that | ||
| 55 | .Fn wcslcpy | ||
| 56 | and | ||
| 57 | .Fn wcslcat | ||
| 58 | only operate on wide strings that are terminated with a null wide character | ||
| 59 | (L'\e0'). | ||
| 60 | This means that for | ||
| 61 | .Fn wcslcpy | ||
| 62 | .Fa src | ||
| 63 | must be terminated with a null wide character and for | ||
| 64 | .Fn wcslcat | ||
| 65 | both | ||
| 66 | .Fa src | ||
| 67 | and | ||
| 68 | .Fa dst | ||
| 69 | must be terminated with a null wide character. | ||
| 70 | .Pp | ||
| 71 | The | ||
| 72 | .Fn wcslcpy | ||
| 73 | function copies up to | ||
| 74 | .Fa size | ||
| 75 | \(mi 1 wide characters from the wide string | ||
| 76 | .Fa src | ||
| 77 | to | ||
| 78 | .Fa dst , | ||
| 79 | terminating the result with a null wide character. | ||
| 80 | .Pp | ||
| 81 | The | ||
| 82 | .Fn wcslcat | ||
| 83 | function appends the wide string | ||
| 84 | .Fa src | ||
| 85 | to the end of | ||
| 86 | .Fa dst . | ||
| 87 | It will append at most | ||
| 88 | .Fa size | ||
| 89 | \(mi wcslen(dst) \(mi 1 wide characters, terminating the result with a null | ||
| 90 | wide character. | ||
| 91 | .Sh RETURN VALUES | ||
| 92 | The | ||
| 93 | .Fn wcslcpy | ||
| 94 | and | ||
| 95 | .Fn wcslcat | ||
| 96 | functions return the total length of the wide string they tried to create. | ||
| 97 | For | ||
| 98 | .Fn wcslcpy | ||
| 99 | that means the length of | ||
| 100 | .Fa src . | ||
| 101 | For | ||
| 102 | .Fn wcslcat | ||
| 103 | that means the initial length of | ||
| 104 | .Fa dst | ||
| 105 | plus | ||
| 106 | the length of | ||
| 107 | .Fa src . | ||
| 108 | While this may seem somewhat confusing, it was done to make | ||
| 109 | truncation detection simple. | ||
| 110 | .Pp | ||
| 111 | Note, however, that if | ||
| 112 | .Fn wcslcat | ||
| 113 | traverses | ||
| 114 | .Fa size | ||
| 115 | wide characters without finding a null wide character, the length of the | ||
| 116 | string is considered to be | ||
| 117 | .Fa size | ||
| 118 | and the destination wide string will not be terminated with a null wide | ||
| 119 | character (since there was no space for it). | ||
| 120 | This keeps | ||
| 121 | .Fn wcslcat | ||
| 122 | from running off the end of a wide string. | ||
| 123 | In practice this should not happen (as it means that either | ||
| 124 | .Fa size | ||
| 125 | is incorrect or that | ||
| 126 | .Fa dst | ||
| 127 | is not terminated with a null wide character). | ||
| 128 | The check exists to prevent potential security problems in incorrect code. | ||
| 129 | .Sh SEE ALSO | ||
| 130 | .Xr swprintf 3 , | ||
| 131 | .Xr wcsncat 3 , | ||
| 132 | .Xr wcsncpy 3 | ||
| 133 | .Sh HISTORY | ||
| 134 | The | ||
| 135 | .Fn wcslcpy | ||
| 136 | and | ||
| 137 | .Fn wcslcat | ||
| 138 | functions first appeared in | ||
| 139 | .Ox 3.8 . | ||
