1memcpy(3) Library Functions Manual memcpy(3)
2
3
4
6 memcpy - copy memory area
7
9 Standard C library (libc, -lc)
10
12 #include <string.h>
13
14 void *memcpy(void dest[restrict .n], const void src[restrict .n],
15 size_t n);
16
18 The memcpy() function copies n bytes from memory area src to memory
19 area dest. The memory areas must not overlap. Use memmove(3) if the
20 memory areas do overlap.
21
23 The memcpy() function returns a pointer to dest.
24
26 For an explanation of the terms used in this section, see at‐
27 tributes(7).
28
29 ┌────────────────────────────────────────────┬───────────────┬─────────┐
30 │Interface │ Attribute │ Value │
31 ├────────────────────────────────────────────┼───────────────┼─────────┤
32 │memcpy() │ Thread safety │ MT-Safe │
33 └────────────────────────────────────────────┴───────────────┴─────────┘
34
36 C11, POSIX.1-2008.
37
39 POSIX.1-2001, C89, SVr4, 4.3BSD.
40
42 Failure to observe the requirement that the memory areas do not overlap
43 has been the source of significant bugs. (POSIX and the C standards
44 are explicit that employing memcpy() with overlapping areas produces
45 undefined behavior.) Most notably, in glibc 2.13 a performance
46 optimization of memcpy() on some platforms (including x86-64) included
47 changing the order in which bytes were copied from src to dest.
48
49 This change revealed breakages in a number of applications that
50 performed copying with overlapping areas. Under the previous
51 implementation, the order in which the bytes were copied had
52 fortuitously hidden the bug, which was revealed when the copying order
53 was reversed. In glibc 2.14, a versioned symbol was added so that old
54 binaries (i.e., those linked against glibc versions earlier than 2.14)
55 employed a memcpy() implementation that safely handles the overlapping
56 buffers case (by providing an "older" memcpy() implementation that was
57 aliased to memmove(3)).
58
60 bcopy(3), bstring(3), memccpy(3), memmove(3), mempcpy(3), strcpy(3),
61 strncpy(3), wmemcpy(3)
62
63
64
65Linux man-pages 6.05 2023-07-20 memcpy(3)