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