Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 16 Mar 2003 18:17:52 -0700 (MST)
From:      "M. Warner Losh" <imp@bsdimp.com>
To:        phk@phk.freebsd.dk
Cc:        arch@FreeBSD.ORG
Subject:   Re: memcpy() with specified direction of copying ?
Message-ID:  <20030316.181752.16867058.imp@bsdimp.com>
In-Reply-To: <9357.1047847012@critter.freebsd.dk>
References:  <9357.1047847012@critter.freebsd.dk>

next in thread | previous in thread | raw e-mail | index | archive | help
In message: <9357.1047847012@critter.freebsd.dk>
            Poul-Henning Kamp <phk@phk.freebsd.dk> writes:
: 
: Is there any standard which has provided an api for mandating the
: direction of copying from a memcpy() like function ?
: 
: As I read our man-page, there is no way to know of memcpy() copies
: from the start and forward or from the end and backward through the
: two areas.

memcpy is not defined when overlapping strings are concerned.  It is
allowed to screw them up in whatever ways are a side effect of the
fastest way to copy memory is.  memmove is well defined here.  It is
slower, but guaranteed to work on overlapping strings.  A string here
is a hunk of memory, not a 'C' string.

       [#2] The memcpy function copies n characters from the object
       pointed  to  by  s2  into  the  object pointed to by s1.  If
       copying  takes  place  between  objects  that  overlap,  the
       behavior is undefined.

       [#2]  The  memmove  function  copies  n  characters from the
       object pointed to by s2 into the object pointed  to  by  s1.
       Copying  takes  place as if the n characters from the object
       pointed to by s2 are first copied into a temporary array  of
       n characters that does not overlap the objects pointed to by
       s1 and s2, and then the  n  characters  from  the  temporary
       array are copied into the object pointed to by s1.

Warner

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-arch" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20030316.181752.16867058.imp>