]> git.ipfire.org Git - thirdparty/man-pages.git/blame_incremental - man3/memcpy.3
err.3: EXAMPLES: use EXIT_FAILURE rather than 1 as exit status
[thirdparty/man-pages.git] / man3 / memcpy.3
... / ...
CommitLineData
1.\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk)
2.\" and Copyright 2015 Michael Kerrisk <mtk.manpages@gmail.com>
3.\"
4.\" %%%LICENSE_START(VERBATIM)
5.\" Permission is granted to make and distribute verbatim copies of this
6.\" manual provided the copyright notice and this permission notice are
7.\" preserved on all copies.
8.\"
9.\" Permission is granted to copy and distribute modified versions of this
10.\" manual under the conditions for verbatim copying, provided that the
11.\" entire resulting derived work is distributed under the terms of a
12.\" permission notice identical to this one.
13.\"
14.\" Since the Linux kernel and libraries are constantly changing, this
15.\" manual page may be incorrect or out-of-date. The author(s) assume no
16.\" responsibility for errors or omissions, or for damages resulting from
17.\" the use of the information contained herein. The author(s) may not
18.\" have taken the same level of care in the production of this manual,
19.\" which is licensed free of charge, as they might when working
20.\" professionally.
21.\"
22.\" Formatted or processed versions of this manual, if unaccompanied by
23.\" the source, must acknowledge the copyright and authors of this work.
24.\" %%%LICENSE_END
25.\"
26.\" References consulted:
27.\" Linux libc source code
28.\" Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991)
29.\" 386BSD man pages
30.\" Modified Sun Jul 25 10:41:09 1993 by Rik Faith (faith@cs.unc.edu)
31.TH MEMCPY 3 2017-09-15 "" "Linux Programmer's Manual"
32.SH NAME
33memcpy \- copy memory area
34.SH SYNOPSIS
35.nf
36.B #include <string.h>
37.PP
38.BI "void *memcpy(void *" dest ", const void *" src ", size_t " n );
39.fi
40.SH DESCRIPTION
41The
42.BR memcpy ()
43function copies \fIn\fP bytes from memory area
44\fIsrc\fP to memory area \fIdest\fP.
45The memory areas must not overlap.
46Use
47.BR memmove (3)
48if the memory areas do overlap.
49.SH RETURN VALUE
50The
51.BR memcpy ()
52function returns a pointer to \fIdest\fP.
53.SH ATTRIBUTES
54For an explanation of the terms used in this section, see
55.BR attributes (7).
56.TS
57allbox;
58lb lb lb
59l l l.
60Interface Attribute Value
61T{
62.BR memcpy ()
63T} Thread safety MT-Safe
64.TE
65.SH CONFORMING TO
66POSIX.1-2001, POSIX.1-2008, C89, C99, SVr4, 4.3BSD.
67.SH NOTES
68Failure to observe the requirement that the memory areas
69do not overlap has been the source of significant bugs.
70(POSIX and the C standards are explicit that employing
71.BR memcpy ()
72with overlapping areas produces undefined behavior.)
73Most notably, in glibc 2.13
74.\" glibc commit 6fb8cbcb58a29fff73eb2101b34caa19a7f88eba
75a performance optimization of
76.BR memcpy ()
77on some platforms (including x86-64) included changing the order
78.\" From forward copying to backward copying
79in which bytes were copied from
80.I src
81to
82.IR dest .
83.PP
84This change revealed breakages in a number of applications that performed
85copying with overlapping areas.
86.\" Adobe Flash player was the highest profile example:
87.\" https://bugzilla.redhat.com/show_bug.cgi?id=638477
88.\" Reported: 2010-09-29 02:35 EDT by JCHuynh
89.\" Bug 638477 - Strange sound on mp3 flash website
90.\"
91.\" https://sourceware.org/bugzilla/show_bug.cgi?id=12518
92.\" Bug 12518 - memcpy acts randomly (and differently) with overlapping areas
93.\" Reported: 2011-02-25 02:26 UTC by Linus Torvalds
94.\"
95Under the previous implementation,
96the order in which the bytes were copied had fortuitously hidden the bug,
97which was revealed when the copying order was reversed.
98In glibc 2.14,
99.\" glibc commit 0354e355014b7bfda32622e0255399d859862fcd
100a versioned symbol was added so that old binaries
101(i.e., those linked against glibc versions earlier than 2.14)
102employed a
103.BR memcpy ()
104implementation that safely handles the overlapping buffers case
105(by providing an "older"
106.BR memcpy ()
107implementation that was aliased to
108.BR memmove (3)).
109.SH SEE ALSO
110.BR bcopy (3),
111.BR bstring (3),
112.BR memccpy (3),
113.BR memmove (3),
114.BR mempcpy (3),
115.BR strcpy (3),
116.BR strncpy (3),
117.BR wmemcpy (3)