1 .\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk)
2 .\" and Copyright 2015 Michael Kerrisk <mtk.manpages@gmail.com>
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.
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.
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
22 .\" Formatted or processed versions of this manual, if unaccompanied by
23 .\" the source, must acknowledge the copyright and authors of this work.
26 .\" References consulted:
27 .\" Linux libc source code
28 .\" Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991)
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"
33 memcpy \- copy memory area
36 .B #include <string.h>
38 .BI "void *memcpy(void *" dest ", const void *" src ", size_t " n );
43 function copies \fIn\fP bytes from memory area
44 \fIsrc\fP to memory area \fIdest\fP.
45 The memory areas must not overlap.
48 if the memory areas do overlap.
52 function returns a pointer to \fIdest\fP.
54 For an explanation of the terms used in this section, see
60 Interface Attribute Value
63 T} Thread safety MT-Safe
66 POSIX.1-2001, POSIX.1-2008, C89, C99, SVr4, 4.3BSD.
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
72 with overlapping areas produces undefined behavior.)
73 Most notably, in glibc 2.13
74 .\" glibc commit 6fb8cbcb58a29fff73eb2101b34caa19a7f88eba
75 a performance optimization of
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
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
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
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.
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)
104 implementation that safely handles the overlapping buffers case
105 (by providing an "older"
107 implementation that was aliased to