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 *dest, const void *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       └──────────┴───────────────┴─────────┘

CONFORMING TO

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

NOTES

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

SEE ALSO

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

COLOPHON

56       This page is part of release 5.10 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)
Impressum