]>
Commit | Line | Data |
---|---|---|
1 | .\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk) | |
2 | .\" and Copyright 2015 Michael Kerrisk <mtk.manpages@gmail.com> | |
3 | .\" | |
4 | .\" %%%LICENSE_START(VERBATIM) | |
5 | .\" Permission is granted to make and distribute verbatim copies of this | |
6 | .\" manual provided the copyright notice and this permission notice are | |
7 | .\" preserved on all copies. | |
8 | .\" | |
9 | .\" Permission is granted to copy and distribute modified versions of this | |
10 | .\" manual under the conditions for verbatim copying, provided that the | |
11 | .\" entire resulting derived work is distributed under the terms of a | |
12 | .\" permission notice identical to this one. | |
13 | .\" | |
14 | .\" Since the Linux kernel and libraries are constantly changing, this | |
15 | .\" manual page may be incorrect or out-of-date. The author(s) assume no | |
16 | .\" responsibility for errors or omissions, or for damages resulting from | |
17 | .\" the use of the information contained herein. The author(s) may not | |
18 | .\" have taken the same level of care in the production of this manual, | |
19 | .\" which is licensed free of charge, as they might when working | |
20 | .\" professionally. | |
21 | .\" | |
22 | .\" Formatted or processed versions of this manual, if unaccompanied by | |
23 | .\" the source, must acknowledge the copyright and authors of this work. | |
24 | .\" %%%LICENSE_END | |
25 | .\" | |
26 | .\" References consulted: | |
27 | .\" Linux libc source code | |
28 | .\" Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991) | |
29 | .\" 386BSD man pages | |
30 | .\" Modified Sun Jul 25 10:41:09 1993 by Rik Faith (faith@cs.unc.edu) | |
31 | .TH MEMCPY 3 2017-09-15 "" "Linux Programmer's Manual" | |
32 | .SH NAME | |
33 | memcpy \- copy memory area | |
34 | .SH SYNOPSIS | |
35 | .nf | |
36 | .B #include <string.h> | |
37 | .PP | |
38 | .BI "void *memcpy(void *" dest ", const void *" src ", size_t " n ); | |
39 | .fi | |
40 | .SH DESCRIPTION | |
41 | The | |
42 | .BR memcpy () | |
43 | function copies \fIn\fP bytes from memory area | |
44 | \fIsrc\fP to memory area \fIdest\fP. | |
45 | The memory areas must not overlap. | |
46 | Use | |
47 | .BR memmove (3) | |
48 | if the memory areas do overlap. | |
49 | .SH RETURN VALUE | |
50 | The | |
51 | .BR memcpy () | |
52 | function returns a pointer to \fIdest\fP. | |
53 | .SH ATTRIBUTES | |
54 | For an explanation of the terms used in this section, see | |
55 | .BR attributes (7). | |
56 | .TS | |
57 | allbox; | |
58 | lb lb lb | |
59 | l l l. | |
60 | Interface Attribute Value | |
61 | T{ | |
62 | .BR memcpy () | |
63 | T} Thread safety MT-Safe | |
64 | .TE | |
65 | .SH CONFORMING TO | |
66 | POSIX.1-2001, POSIX.1-2008, C89, C99, SVr4, 4.3BSD. | |
67 | .SH NOTES | |
68 | Failure to observe the requirement that the memory areas | |
69 | do not overlap has been the source of significant bugs. | |
70 | (POSIX and the C standards are explicit that employing | |
71 | .BR memcpy () | |
72 | with overlapping areas produces undefined behavior.) | |
73 | Most notably, in glibc 2.13 | |
74 | .\" glibc commit 6fb8cbcb58a29fff73eb2101b34caa19a7f88eba | |
75 | a performance optimization of | |
76 | .BR memcpy () | |
77 | on some platforms (including x86-64) included changing the order | |
78 | .\" From forward copying to backward copying | |
79 | in which bytes were copied from | |
80 | .I src | |
81 | to | |
82 | .IR dest . | |
83 | .PP | |
84 | This change revealed breakages in a number of applications that performed | |
85 | copying with overlapping areas. | |
86 | .\" Adobe Flash player was the highest profile example: | |
87 | .\" https://bugzilla.redhat.com/show_bug.cgi?id=638477 | |
88 | .\" Reported: 2010-09-29 02:35 EDT by JCHuynh | |
89 | .\" Bug 638477 - Strange sound on mp3 flash website | |
90 | .\" | |
91 | .\" https://sourceware.org/bugzilla/show_bug.cgi?id=12518 | |
92 | .\" Bug 12518 - memcpy acts randomly (and differently) with overlapping areas | |
93 | .\" Reported: 2011-02-25 02:26 UTC by Linus Torvalds | |
94 | .\" | |
95 | Under the previous implementation, | |
96 | the order in which the bytes were copied had fortuitously hidden the bug, | |
97 | which was revealed when the copying order was reversed. | |
98 | In glibc 2.14, | |
99 | .\" glibc commit 0354e355014b7bfda32622e0255399d859862fcd | |
100 | a versioned symbol was added so that old binaries | |
101 | (i.e., those linked against glibc versions earlier than 2.14) | |
102 | employed a | |
103 | .BR memcpy () | |
104 | implementation that safely handles the overlapping buffers case | |
105 | (by providing an "older" | |
106 | .BR memcpy () | |
107 | implementation that was aliased to | |
108 | .BR memmove (3)). | |
109 | .SH SEE ALSO | |
110 | .BR bcopy (3), | |
111 | .BR bstring (3), | |
112 | .BR memccpy (3), | |
113 | .BR memmove (3), | |
114 | .BR mempcpy (3), | |
115 | .BR strcpy (3), | |
116 | .BR strncpy (3), | |
117 | .BR wmemcpy (3) |