diff options
| author | millert <> | 2013-12-19 20:52:37 +0000 |
|---|---|---|
| committer | millert <> | 2013-12-19 20:52:37 +0000 |
| commit | 062d999e00c36692605b1ac394ffcfbb340e1771 (patch) | |
| tree | ef71f36904bc7ca141dbe9cf9a9504e688b183c3 /src/lib/libc/string/strcpy.3 | |
| parent | 3c960933763956e6ab55d204e71d003e258f726a (diff) | |
| download | openbsd-062d999e00c36692605b1ac394ffcfbb340e1771.tar.gz openbsd-062d999e00c36692605b1ac394ffcfbb340e1771.tar.bz2 openbsd-062d999e00c36692605b1ac394ffcfbb340e1771.zip | |
Split out strncpy and strncat from strcpy and strcat manuals.
Requested by deraadt@
Diffstat (limited to 'src/lib/libc/string/strcpy.3')
| -rw-r--r-- | src/lib/libc/string/strcpy.3 | 98 |
1 files changed, 10 insertions, 88 deletions
diff --git a/src/lib/libc/string/strcpy.3 b/src/lib/libc/string/strcpy.3 index 798c7e8d99..849184d1f5 100644 --- a/src/lib/libc/string/strcpy.3 +++ b/src/lib/libc/string/strcpy.3 | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | .\" $OpenBSD: strcpy.3,v 1.19 2013/09/25 21:49:31 millert Exp $ | 1 | .\" $OpenBSD: strcpy.3,v 1.20 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,52 +31,31 @@ | |||
| 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: September 25 2013 $ | 34 | .Dd $Mdocdate: December 19 2013 $ |
| 35 | .Dt STRCPY 3 | 35 | .Dt STRCPY 3 |
| 36 | .Os | 36 | .Os |
| 37 | .Sh NAME | 37 | .Sh NAME |
| 38 | .Nm strcpy , | 38 | .Nm strcpy |
| 39 | .Nm strncpy | 39 | .Nd copy a string |
| 40 | .Nd copy strings | ||
| 41 | .Sh SYNOPSIS | 40 | .Sh SYNOPSIS |
| 42 | .In string.h | 41 | .In string.h |
| 43 | .Ft char * | 42 | .Ft char * |
| 44 | .Fn strcpy "char *dst" "const char *src" | 43 | .Fn strcpy "char *dst" "const char *src" |
| 45 | .Ft char * | ||
| 46 | .Fn strncpy "char *dst" "const char *src" "size_t len" | ||
| 47 | .Sh DESCRIPTION | 44 | .Sh DESCRIPTION |
| 48 | The | 45 | The |
| 49 | .Fn strcpy | 46 | .Fn strcpy |
| 50 | and | 47 | function copies the string |
| 51 | .Fn strncpy | ||
| 52 | functions copy the string | ||
| 53 | .Fa src | 48 | .Fa src |
| 54 | to | 49 | to |
| 55 | .Fa dst | 50 | .Fa dst |
| 56 | (including the terminating | 51 | (including the terminating |
| 57 | .Ql \e0 | 52 | .Ql \e0 |
| 58 | character). | 53 | character). |
| 59 | .Pp | 54 | The string |
| 60 | The | ||
| 61 | .Fn strncpy | ||
| 62 | function copies not more than | ||
| 63 | .Fa len | ||
| 64 | characters into | ||
| 65 | .Fa dst , | ||
| 66 | appending | ||
| 67 | .Ql \e0 | ||
| 68 | characters if | ||
| 69 | .Fa src | ||
| 70 | is less than | ||
| 71 | .Fa len | ||
| 72 | characters long, and | ||
| 73 | .Em not | ||
| 74 | terminating | ||
| 75 | .Fa dst | 55 | .Fa dst |
| 76 | if the length of | 56 | must be at least as large as |
| 77 | .Fa src | 57 | .Fa src |
| 78 | is greater than or equal to | 58 | to hold the result. |
| 79 | .Fa len . | ||
| 80 | .Pp | 59 | .Pp |
| 81 | If the | 60 | If the |
| 82 | .Fa src | 61 | .Fa src |
| @@ -86,63 +65,8 @@ strings overlap, the behavior is undefined. | |||
| 86 | .Sh RETURN VALUES | 65 | .Sh RETURN VALUES |
| 87 | The | 66 | The |
| 88 | .Fn strcpy | 67 | .Fn strcpy |
| 89 | and | 68 | function returns |
| 90 | .Fn strncpy | ||
| 91 | functions return | ||
| 92 | .Fa dst . | 69 | .Fa dst . |
| 93 | .Sh EXAMPLES | ||
| 94 | The following sets | ||
| 95 | .Va chararray | ||
| 96 | to | ||
| 97 | .Dq abc\e0\e0\e0 : | ||
| 98 | .Bd -literal -offset indent | ||
| 99 | (void)strncpy(chararray, "abc", 6); | ||
| 100 | .Ed | ||
| 101 | .Pp | ||
| 102 | The following sets | ||
| 103 | .Va chararray | ||
| 104 | to | ||
| 105 | .Dq abcdef | ||
| 106 | and does | ||
| 107 | .Em not | ||
| 108 | NUL terminate | ||
| 109 | .Va chararray | ||
| 110 | because the length of the source string is greater than or equal to the | ||
| 111 | length parameter. | ||
| 112 | .Fn strncpy | ||
| 113 | .Em only | ||
| 114 | NUL terminates the destination string when the length of the source | ||
| 115 | string is less than the length parameter. | ||
| 116 | .Bd -literal -offset indent | ||
| 117 | (void)strncpy(chararray, "abcdefgh", 6); | ||
| 118 | .Ed | ||
| 119 | .Pp | ||
| 120 | The following copies as many characters from | ||
| 121 | .Va input | ||
| 122 | to | ||
| 123 | .Va buf | ||
| 124 | as will fit and NUL terminates the result. | ||
| 125 | Because | ||
| 126 | .Fn strncpy | ||
| 127 | does | ||
| 128 | .Em not | ||
| 129 | guarantee to NUL terminate the string itself, it must be done by hand. | ||
| 130 | .Bd -literal -offset indent | ||
| 131 | char buf[BUFSIZ]; | ||
| 132 | |||
| 133 | (void)strncpy(buf, input, sizeof(buf) - 1); | ||
| 134 | buf[sizeof(buf) - 1] = '\e0'; | ||
| 135 | .Ed | ||
| 136 | .Pp | ||
| 137 | Note that | ||
| 138 | .Xr strlcpy 3 | ||
| 139 | is a better choice for this kind of operation. | ||
| 140 | The equivalent using | ||
| 141 | .Xr strlcpy 3 | ||
| 142 | is simply: | ||
| 143 | .Bd -literal -offset indent | ||
| 144 | (void)strlcpy(buf, input, sizeof(buf)); | ||
| 145 | .Ed | ||
| 146 | .Sh SEE ALSO | 70 | .Sh SEE ALSO |
| 147 | .Xr bcopy 3 , | 71 | .Xr bcopy 3 , |
| 148 | .Xr memccpy 3 , | 72 | .Xr memccpy 3 , |
| @@ -150,6 +74,7 @@ is simply: | |||
| 150 | .Xr memmove 3 , | 74 | .Xr memmove 3 , |
| 151 | .Xr strcat 3 , | 75 | .Xr strcat 3 , |
| 152 | .Xr strlcpy 3 , | 76 | .Xr strlcpy 3 , |
| 77 | .Xr strncpy 3 , | ||
| 153 | .Xr wcscpy 3 , | 78 | .Xr wcscpy 3 , |
| 154 | .Xr wcslcpy 3 | 79 | .Xr wcslcpy 3 |
| 155 | .Sh STANDARDS | 80 | .Sh STANDARDS |
| @@ -164,7 +89,4 @@ The | |||
| 164 | .Fn strcpy | 89 | .Fn strcpy |
| 165 | function first appeared in the Programmer's Workbench (PWB/UNIX) | 90 | function first appeared in the Programmer's Workbench (PWB/UNIX) |
| 166 | and was ported to | 91 | and was ported to |
| 167 | .At v7 ; | ||
| 168 | .Fn strncpy | ||
| 169 | first appeared in | ||
| 170 | .At v7 . | 92 | .At v7 . |
