1MEMCPY(3) Linux Programmer's Manual MEMCPY(3)
2
3
4
6 memcpy - copy memory area
7
9 #include <string.h>
10
11 void *memcpy(void *dest, const void *src, size_t n);
12
14 The memcpy() function copies n bytes from memory area src to memory
15 area dest. The memory areas must not overlap. Use memmove(3) if the
16 memory areas do overlap.
17
19 The memcpy() function returns a pointer to dest.
20
22 For an explanation of the terms used in this section, see
23 attributes(7).
24
25 ┌──────────┬───────────────┬─────────┐
26 │Interface │ Attribute │ Value │
27 ├──────────┼───────────────┼─────────┤
28 │memcpy() │ Thread safety │ MT-Safe │
29 └──────────┴───────────────┴─────────┘
31 POSIX.1-2001, POSIX.1-2008, C89, C99, SVr4, 4.3BSD.
32
34 Failure to observe the requirement that the memory areas do not overlap
35 has been the source of significant bugs. (POSIX and the C standards
36 are explicit that employing memcpy() with overlapping areas produces
37 undefined behavior.) Most notably, in glibc 2.13 a performance opti‐
38 mization of memcpy() on some platforms (including x86-64) included
39 changing the order in which bytes were copied from src to dest.
40
41 This change revealed breakages in a number of applications that per‐
42 formed copying with overlapping areas. Under the previous implementa‐
43 tion, the order in which the bytes were copied had fortuitously hidden
44 the bug, which was revealed when the copying order was reversed. In
45 glibc 2.14, a versioned symbol was added so that old binaries (i.e.,
46 those linked against glibc versions earlier than 2.14) employed a mem‐
47 cpy() implementation that safely handles the overlapping buffers case
48 (by providing an "older" memcpy() implementation that was aliased to
49 memmove(3)).
50
52 bcopy(3), bstring(3), memccpy(3), memmove(3), mempcpy(3), strcpy(3),
53 strncpy(3), wmemcpy(3)
54
56 This page is part of release 5.04 of the Linux man-pages project. A
57 description of the project, information about reporting bugs, and the
58 latest version of this page, can be found at
59 https://www.kernel.org/doc/man-pages/.
60
61
62
63 2017-09-15 MEMCPY(3)