1memcpy(3)                  Library Functions Manual                  memcpy(3)
2
3
4

NAME

6       memcpy - copy memory area
7

LIBRARY

9       Standard C library (libc, -lc)
10

SYNOPSIS

12       #include <string.h>
13
14       void *memcpy(void dest[restrict .n], const void src[restrict .n],
15                    size_t n);
16

DESCRIPTION

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

RETURN VALUE

23       The memcpy() function returns a pointer to dest.
24

ATTRIBUTES

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

STANDARDS

36       C11, POSIX.1-2008.
37

HISTORY

39       POSIX.1-2001, C89, SVr4, 4.3BSD.
40

CAVEATS

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 opti‐
46       mization 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 per‐
50       formed copying with overlapping areas.  Under the previous  implementa‐
51       tion,  the order in which the bytes were copied had fortuitously hidden
52       the bug, which was revealed when the copying order  was  reversed.   In
53       glibc  2.14,  a  versioned symbol was added so that old binaries (i.e.,
54       those linked against glibc versions earlier than 2.14) employed a  mem‐
55       cpy()  implementation  that safely handles the overlapping buffers case
56       (by providing an "older" memcpy() implementation that  was  aliased  to
57       memmove(3)).
58

SEE ALSO

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.04              2023-03-30                         memcpy(3)
Impressum