]>
Commit | Line | Data |
---|---|---|
fea681da | 1 | .\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk) |
023ad3b1 | 2 | .\" and Copyright 2015 Michael Kerrisk <mtk.manpages@gmail.com> |
fea681da | 3 | .\" |
93015253 | 4 | .\" %%%LICENSE_START(VERBATIM) |
fea681da MK |
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. | |
c13182ef | 13 | .\" |
fea681da MK |
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. | |
c13182ef | 21 | .\" |
fea681da MK |
22 | .\" Formatted or processed versions of this manual, if unaccompanied by |
23 | .\" the source, must acknowledge the copyright and authors of this work. | |
4b72fb64 | 24 | .\" %%%LICENSE_END |
fea681da MK |
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) | |
4b8c67d9 | 31 | .TH MEMCPY 3 2017-09-15 "" "Linux Programmer's Manual" |
fea681da MK |
32 | .SH NAME |
33 | memcpy \- copy memory area | |
34 | .SH SYNOPSIS | |
35 | .nf | |
36 | .B #include <string.h> | |
68e4db0a | 37 | .PP |
fea681da MK |
38 | .BI "void *memcpy(void *" dest ", const void *" src ", size_t " n ); |
39 | .fi | |
40 | .SH DESCRIPTION | |
60a90ecd MK |
41 | The |
42 | .BR memcpy () | |
43 | function copies \fIn\fP bytes from memory area | |
c13182ef | 44 | \fIsrc\fP to memory area \fIdest\fP. |
be78d881 | 45 | The memory areas must not overlap. |
60a90ecd MK |
46 | Use |
47 | .BR memmove (3) | |
48 | if the memory areas do overlap. | |
47297adb | 49 | .SH RETURN VALUE |
60a90ecd MK |
50 | The |
51 | .BR memcpy () | |
52 | function returns a pointer to \fIdest\fP. | |
e7c6dacd | 53 | .SH ATTRIBUTES |
09ecd54e PH |
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{ | |
e7c6dacd | 62 | .BR memcpy () |
09ecd54e PH |
63 | T} Thread safety MT-Safe |
64 | .TE | |
47297adb | 65 | .SH CONFORMING TO |
210be529 | 66 | POSIX.1-2001, POSIX.1-2008, C89, C99, SVr4, 4.3BSD. |
023ad3b1 MK |
67 | .SH NOTES |
68 | Failure to observe the requirement that the memory areas | |
475fea9a | 69 | do not overlap has been the source of significant bugs. |
023ad3b1 MK |
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 . | |
847e0d88 | 83 | .PP |
023ad3b1 MK |
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)). | |
47297adb | 109 | .SH SEE ALSO |
fea681da | 110 | .BR bcopy (3), |
879091c9 | 111 | .BR bstring (3), |
fea681da MK |
112 | .BR memccpy (3), |
113 | .BR memmove (3), | |
114 | .BR mempcpy (3), | |
115 | .BR strcpy (3), | |
116 | .BR strncpy (3), | |
117 | .BR wmemcpy (3) |