From owner-freebsd-arch Sun Mar 16 17:19:19 2003 Delivered-To: freebsd-arch@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 1B07137B401 for ; Sun, 16 Mar 2003 17:19:18 -0800 (PST) Received: from harmony.village.org (rover.bsdimp.com [204.144.255.66]) by mx1.FreeBSD.org (Postfix) with ESMTP id F016A43FAF for ; Sun, 16 Mar 2003 17:19:16 -0800 (PST) (envelope-from imp@bsdimp.com) Received: from localhost (warner@rover2.village.org [10.0.0.1]) by harmony.village.org (8.12.8/8.12.3) with ESMTP id h2H1JBA7015648; Sun, 16 Mar 2003 18:19:14 -0700 (MST) (envelope-from imp@bsdimp.com) Date: Sun, 16 Mar 2003 18:17:52 -0700 (MST) Message-Id: <20030316.181752.16867058.imp@bsdimp.com> To: phk@phk.freebsd.dk Cc: arch@FreeBSD.ORG Subject: Re: memcpy() with specified direction of copying ? From: "M. Warner Losh" In-Reply-To: <9357.1047847012@critter.freebsd.dk> References: <9357.1047847012@critter.freebsd.dk> X-Mailer: Mew version 2.1 on Emacs 21.2 / Mule 5.0 (SAKAKI) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit Sender: owner-freebsd-arch@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG In message: <9357.1047847012@critter.freebsd.dk> Poul-Henning Kamp 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