diff options
Diffstat (limited to '')
| -rw-r--r-- | src/lib/libc/string/strcpy.3 | 151 |
1 files changed, 151 insertions, 0 deletions
diff --git a/src/lib/libc/string/strcpy.3 b/src/lib/libc/string/strcpy.3 new file mode 100644 index 0000000000..428e474d43 --- /dev/null +++ b/src/lib/libc/string/strcpy.3 | |||
| @@ -0,0 +1,151 @@ | |||
| 1 | .\" Copyright (c) 1990, 1991 The Regents of the University of California. | ||
| 2 | .\" All rights reserved. | ||
| 3 | .\" | ||
| 4 | .\" This code is derived from software contributed to Berkeley by | ||
| 5 | .\" Chris Torek and the American National Standards Committee X3, | ||
| 6 | .\" on Information Processing Systems. | ||
| 7 | .\" | ||
| 8 | .\" Redistribution and use in source and binary forms, with or without | ||
| 9 | .\" modification, are permitted provided that the following conditions | ||
| 10 | .\" are met: | ||
| 11 | .\" 1. Redistributions of source code must retain the above copyright | ||
| 12 | .\" notice, this list of conditions and the following disclaimer. | ||
| 13 | .\" 2. Redistributions in binary form must reproduce the above copyright | ||
| 14 | .\" notice, this list of conditions and the following disclaimer in the | ||
| 15 | .\" documentation and/or other materials provided with the distribution. | ||
| 16 | .\" 3. Neither the name of the University nor the names of its contributors | ||
| 17 | .\" may be used to endorse or promote products derived from this software | ||
| 18 | .\" without specific prior written permission. | ||
| 19 | .\" | ||
| 20 | .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | ||
| 21 | .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 22 | .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 23 | .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | ||
| 24 | .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 25 | .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 26 | .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 27 | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 28 | .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 29 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 30 | .\" SUCH DAMAGE. | ||
| 31 | .\" | ||
| 32 | .\" $OpenBSD: strcpy.3,v 1.15 2007/05/31 19:19:32 jmc Exp $ | ||
| 33 | .\" | ||
| 34 | .Dd $Mdocdate: May 31 2007 $ | ||
| 35 | .Dt STRCPY 3 | ||
| 36 | .Os | ||
| 37 | .Sh NAME | ||
| 38 | .Nm strcpy , | ||
| 39 | .Nm strncpy | ||
| 40 | .Nd copy strings | ||
| 41 | .Sh SYNOPSIS | ||
| 42 | .Fd #include <string.h> | ||
| 43 | .Ft char * | ||
| 44 | .Fn strcpy "char *dst" "const char *src" | ||
| 45 | .Ft char * | ||
| 46 | .Fn strncpy "char *dst" "const char *src" "size_t len" | ||
| 47 | .Sh DESCRIPTION | ||
| 48 | The | ||
| 49 | .Fn strcpy | ||
| 50 | and | ||
| 51 | .Fn strncpy | ||
| 52 | functions copy the string | ||
| 53 | .Fa src | ||
| 54 | to | ||
| 55 | .Fa dst | ||
| 56 | (including the terminating | ||
| 57 | .Ql \e0 | ||
| 58 | character). | ||
| 59 | .Pp | ||
| 60 | .Fn strncpy | ||
| 61 | copies not more than | ||
| 62 | .Fa len | ||
| 63 | characters into | ||
| 64 | .Fa dst , | ||
| 65 | appending | ||
| 66 | .Ql \e0 | ||
| 67 | characters if | ||
| 68 | .Fa src | ||
| 69 | is less than | ||
| 70 | .Fa len | ||
| 71 | characters long, and | ||
| 72 | .Em not | ||
| 73 | terminating | ||
| 74 | .Fa dst | ||
| 75 | if the length of | ||
| 76 | .Fa src | ||
| 77 | is greater than or equal to | ||
| 78 | .Fa len . | ||
| 79 | .Sh RETURN VALUES | ||
| 80 | The | ||
| 81 | .Fn strcpy | ||
| 82 | and | ||
| 83 | .Fn strncpy | ||
| 84 | functions return | ||
| 85 | .Fa dst . | ||
| 86 | .Sh EXAMPLES | ||
| 87 | The following sets | ||
| 88 | .Va chararray | ||
| 89 | to | ||
| 90 | .Dq abc\e0\e0\e0 : | ||
| 91 | .Bd -literal -offset indent | ||
| 92 | (void)strncpy(chararray, "abc", 6); | ||
| 93 | .Ed | ||
| 94 | .Pp | ||
| 95 | The following sets | ||
| 96 | .Va chararray | ||
| 97 | to | ||
| 98 | .Dq abcdef | ||
| 99 | and does | ||
| 100 | .Em not | ||
| 101 | NUL terminate | ||
| 102 | .Va chararray | ||
| 103 | because the length of the source string is greater than or equal to the | ||
| 104 | length parameter. | ||
| 105 | .Fn strncpy | ||
| 106 | .Em only | ||
| 107 | NUL terminates the destination string when the length of the source | ||
| 108 | string is less than the length parameter. | ||
| 109 | .Bd -literal -offset indent | ||
| 110 | (void)strncpy(chararray, "abcdefgh", 6); | ||
| 111 | .Ed | ||
| 112 | .Pp | ||
| 113 | The following copies as many characters from | ||
| 114 | .Va input | ||
| 115 | to | ||
| 116 | .Va buf | ||
| 117 | as will fit and NUL terminates the result. | ||
| 118 | Because | ||
| 119 | .Fn strncpy | ||
| 120 | does | ||
| 121 | .Em not | ||
| 122 | guarantee to NUL terminate the string itself, it must be done by hand. | ||
| 123 | .Bd -literal -offset indent | ||
| 124 | char buf[BUFSIZ]; | ||
| 125 | |||
| 126 | (void)strncpy(buf, input, sizeof(buf) - 1); | ||
| 127 | buf[sizeof(buf) - 1] = '\e0'; | ||
| 128 | .Ed | ||
| 129 | .Pp | ||
| 130 | Note that | ||
| 131 | .Xr strlcpy 3 | ||
| 132 | is a better choice for this kind of operation. | ||
| 133 | The equivalent using | ||
| 134 | .Xr strlcpy 3 | ||
| 135 | is simply: | ||
| 136 | .Bd -literal -offset indent | ||
| 137 | (void)strlcpy(buf, input, sizeof(buf)); | ||
| 138 | .Ed | ||
| 139 | .Sh SEE ALSO | ||
| 140 | .Xr bcopy 3 , | ||
| 141 | .Xr memccpy 3 , | ||
| 142 | .Xr memcpy 3 , | ||
| 143 | .Xr memmove 3 , | ||
| 144 | .Xr strlcpy 3 | ||
| 145 | .Sh STANDARDS | ||
| 146 | The | ||
| 147 | .Fn strcpy | ||
| 148 | and | ||
| 149 | .Fn strncpy | ||
| 150 | functions conform to | ||
| 151 | .St -ansiC . | ||
