diff options
Diffstat (limited to 'src/lib/libc/string/strcpy.3')
| -rw-r--r-- | src/lib/libc/string/strcpy.3 | 96 |
1 files changed, 68 insertions, 28 deletions
diff --git a/src/lib/libc/string/strcpy.3 b/src/lib/libc/string/strcpy.3 index 1ca12c2707..400eeee622 100644 --- a/src/lib/libc/string/strcpy.3 +++ b/src/lib/libc/string/strcpy.3 | |||
| @@ -1,3 +1,5 @@ | |||
| 1 | .\" $OpenBSD: strcpy.3,v 1.16 2011/07/25 00:38:53 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: @(#)strcpy.3 5.4 (Berkeley) 6/29/91 | 34 | .Dd $Mdocdate: July 25 2011 $ |
| 37 | .\" $Id: strcpy.3,v 1.1.1.1 1995/10/18 08:42:22 deraadt Exp $ | ||
| 38 | .\" | ||
| 39 | .Dd June 29, 1991 | ||
| 40 | .Dt STRCPY 3 | 35 | .Dt STRCPY 3 |
| 41 | .Os BSD 4 | 36 | .Os |
| 42 | .Sh NAME | 37 | .Sh NAME |
| 43 | .Nm strcpy | 38 | .Nm strcpy , |
| 39 | .Nm strncpy | ||
| 44 | .Nd copy strings | 40 | .Nd copy strings |
| 45 | .Sh SYNOPSIS | 41 | .Sh SYNOPSIS |
| 46 | .Fd #include <string.h> | 42 | .Fd #include <string.h> |
| @@ -53,8 +49,7 @@ The | |||
| 53 | .Fn strcpy | 49 | .Fn strcpy |
| 54 | and | 50 | and |
| 55 | .Fn strncpy | 51 | .Fn strncpy |
| 56 | functions | 52 | functions copy the string |
| 57 | copy the string | ||
| 58 | .Fa src | 53 | .Fa src |
| 59 | to | 54 | to |
| 60 | .Fa dst | 55 | .Fa dst |
| @@ -64,7 +59,7 @@ character). | |||
| 64 | .Pp | 59 | .Pp |
| 65 | The | 60 | The |
| 66 | .Fn strncpy | 61 | .Fn strncpy |
| 67 | copies not more than | 62 | function copies not more than |
| 68 | .Fa len | 63 | .Fa len |
| 69 | characters into | 64 | characters into |
| 70 | .Fa dst , | 65 | .Fa dst , |
| @@ -78,45 +73,90 @@ characters long, and | |||
| 78 | .Em not | 73 | .Em not |
| 79 | terminating | 74 | terminating |
| 80 | .Fa dst | 75 | .Fa dst |
| 81 | if | 76 | if the length of |
| 82 | .Fa src | 77 | .Fa src |
| 83 | is more than | 78 | is greater than or equal to |
| 84 | .Fa len | 79 | .Fa len . |
| 85 | characters long. | ||
| 86 | .Sh RETURN VALUES | 80 | .Sh RETURN VALUES |
| 87 | The | 81 | The |
| 88 | .Fn strcpy | 82 | .Fn strcpy |
| 89 | and | 83 | and |
| 90 | .Fn strncpy | 84 | .Fn strncpy |
| 91 | functions | 85 | functions return |
| 92 | return | ||
| 93 | .Fa dst . | 86 | .Fa dst . |
| 94 | .Sh EXAMPLES | 87 | .Sh EXAMPLES |
| 95 | The following sets | 88 | The following sets |
| 96 | .Dq Li chararray | 89 | .Va chararray |
| 97 | to | 90 | to |
| 98 | .Dq Li abc\e0\e0\e0 : | 91 | .Dq abc\e0\e0\e0 : |
| 99 | .Bd -literal -offset indent | 92 | .Bd -literal -offset indent |
| 100 | (void)strncpy(chararray, "abc", 6). | 93 | (void)strncpy(chararray, "abc", 6); |
| 101 | .Ed | 94 | .Ed |
| 102 | .Pp | 95 | .Pp |
| 103 | The following sets | 96 | The following sets |
| 104 | .Dq Li chararray | 97 | .Va chararray |
| 105 | to | 98 | to |
| 106 | .Dq Li abcdef : | 99 | .Dq abcdef |
| 100 | and does | ||
| 101 | .Em not | ||
| 102 | NUL terminate | ||
| 103 | .Va chararray | ||
| 104 | because the length of the source string is greater than or equal to the | ||
| 105 | length parameter. | ||
| 106 | .Fn strncpy | ||
| 107 | .Em only | ||
| 108 | NUL terminates the destination string when the length of the source | ||
| 109 | string is less than the length parameter. | ||
| 107 | .Bd -literal -offset indent | 110 | .Bd -literal -offset indent |
| 108 | (void)strncpy(chararray, "abcdefgh", 6); | 111 | (void)strncpy(chararray, "abcdefgh", 6); |
| 109 | .Ed | 112 | .Ed |
| 113 | .Pp | ||
| 114 | The following copies as many characters from | ||
| 115 | .Va input | ||
| 116 | to | ||
| 117 | .Va buf | ||
| 118 | as will fit and NUL terminates the result. | ||
| 119 | Because | ||
| 120 | .Fn strncpy | ||
| 121 | does | ||
| 122 | .Em not | ||
| 123 | guarantee to NUL terminate the string itself, it must be done by hand. | ||
| 124 | .Bd -literal -offset indent | ||
| 125 | char buf[BUFSIZ]; | ||
| 126 | |||
| 127 | (void)strncpy(buf, input, sizeof(buf) - 1); | ||
| 128 | buf[sizeof(buf) - 1] = '\e0'; | ||
| 129 | .Ed | ||
| 130 | .Pp | ||
| 131 | Note that | ||
| 132 | .Xr strlcpy 3 | ||
| 133 | is a better choice for this kind of operation. | ||
| 134 | The equivalent using | ||
| 135 | .Xr strlcpy 3 | ||
| 136 | is simply: | ||
| 137 | .Bd -literal -offset indent | ||
| 138 | (void)strlcpy(buf, input, sizeof(buf)); | ||
| 139 | .Ed | ||
| 110 | .Sh SEE ALSO | 140 | .Sh SEE ALSO |
| 111 | .Xr bcopy 3 , | 141 | .Xr bcopy 3 , |
| 112 | .Xr memccpy 3 , | 142 | .Xr memccpy 3 , |
| 113 | .Xr memcpy 3 , | 143 | .Xr memcpy 3 , |
| 114 | .Xr memmove 3 | 144 | .Xr memmove 3 , |
| 145 | .Xr strcat 3 , | ||
| 146 | .Xr strlcpy 3 , | ||
| 147 | .Xr wcscpy 3 , | ||
| 148 | .Xr wcslcpy 3 | ||
| 115 | .Sh STANDARDS | 149 | .Sh STANDARDS |
| 116 | The | 150 | The |
| 117 | .Fn strcpy | 151 | .Fn strcpy |
| 118 | and | 152 | and |
| 119 | .Fn strncpy | 153 | .Fn strncpy |
| 120 | functions | 154 | functions conform to |
| 121 | conform to | ||
| 122 | .St -ansiC . | 155 | .St -ansiC . |
| 156 | .Sh HISTORY | ||
| 157 | The | ||
| 158 | .Fn strcpy | ||
| 159 | and | ||
| 160 | .Fn strncpy | ||
| 161 | functions first appeared in | ||
| 162 | .At v7 . | ||
