1MEMCPY(3)                  Linux Programmer's Manual                 MEMCPY(3)
2
3
4

NAME

6       memcpy - copy memory area
7

SYNOPSIS

9       #include <string.h>
10
11       void *memcpy(void *restrict dest, const void *restrict src, size_t n);
12

DESCRIPTION

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

RETURN VALUE

19       The memcpy() function returns a pointer to dest.
20

ATTRIBUTES

22       For  an  explanation  of  the  terms  used  in  this  section,  see at‐
23       tributes(7).
24
25       ┌────────────────────────────────────────────┬───────────────┬─────────┐
26Interface                                   Attribute     Value   
27       ├────────────────────────────────────────────┼───────────────┼─────────┤
28memcpy()                                    │ Thread safety │ MT-Safe │
29       └────────────────────────────────────────────┴───────────────┴─────────┘
30

CONFORMING TO

32       POSIX.1-2001, POSIX.1-2008, C89, C99, SVr4, 4.3BSD.
33

NOTES

35       Failure to observe the requirement that the memory areas do not overlap
36       has  been  the  source of significant bugs.  (POSIX and the C standards
37       are explicit that employing memcpy() with  overlapping  areas  produces
38       undefined  behavior.)   Most notably, in glibc 2.13 a performance opti‐
39       mization of memcpy() on  some  platforms  (including  x86-64)  included
40       changing the order in which bytes were copied from src to dest.
41
42       This  change  revealed  breakages in a number of applications that per‐
43       formed copying with overlapping areas.  Under the previous  implementa‐
44       tion,  the order in which the bytes were copied had fortuitously hidden
45       the bug, which was revealed when the copying order  was  reversed.   In
46       glibc  2.14,  a  versioned symbol was added so that old binaries (i.e.,
47       those linked against glibc versions earlier than 2.14) employed a  mem‐
48       cpy()  implementation  that safely handles the overlapping buffers case
49       (by providing an "older" memcpy() implementation that  was  aliased  to
50       memmove(3)).
51

SEE ALSO

53       bcopy(3),  bstring(3),  memccpy(3),  memmove(3), mempcpy(3), strcpy(3),
54       strncpy(3), wmemcpy(3)
55

COLOPHON

57       This page is part of release 5.12 of the Linux  man-pages  project.   A
58       description  of  the project, information about reporting bugs, and the
59       latest    version    of    this    page,    can     be     found     at
60       https://www.kernel.org/doc/man-pages/.
61
62
63
64                                  2021-03-22                         MEMCPY(3)
Impressum