Xref: utzoo comp.lang.c:29602 comp.sys.att:9797 Path: utzoo!utgpu!news-server.csri.toronto.edu!clyde.concordia.ca!uunet!snorkelwacker!spdcc!ima!haddock!karl From: karl@haddock.ima.isc.com (Karl Heuer) Newsgroups: comp.lang.c,comp.sys.att Subject: Re: bcopy and bzero on AT&T sysV Keywords: bcopy bzero AT&T Message-ID: <16891@haddock.ima.isc.com> Date: 15 Jun 90 01:36:48 GMT References: <213@cti1.UUCP> <1990Jun14.233837.22318@virtech.uucp> Reply-To: karl@haddock.ima.isc.com (Karl Heuer) Organization: Interactive Systems, Cambridge, MA 02138-5302 Lines: 36 In article <1990Jun14.233837.22318@virtech.uucp> cpcahil@virtech.UUCP (Conor P. Cahill) writes: >Note that memcpy is not guarranteed to handle overlapping moves, while >bcopy is assumed to by some programs. Despite the fact that bcopy is also not guaranteed to handle them (at least not in the 4.3BSD man page), and often doesn't. It's better to use the mem-functions directly rather than the b-functions, since the former are part of the ANSI Standard library, and since they allow you to specify whether you need the additional semantics of overlapping moves (memmove() vs. memcpy()). If you need memmove() and your implementation doesn't support the Standard library yet, the enclosed source may help. Karl W. Z. Heuer (karl@ima.ima.isc.com or harvard!ima!karl), The Walking Lint --------cut here-------- #include /* * Same as memcpy, but with guaranteed semantics on overlap. This algorithm * assumes trichotomy is valid even when the operands don't point into the * same array. */ void *memmove(void *adest, void *asrc, size_t n) { if (n != 0) { register char *dest = (char *)adest; register char *src = (char *)asrc; if (src > dest) { do *dest++ = *src++; while (--n != 0); } else if (src < dest) { src += n; dest += n; do *--dest = *--src; while (--n != 0); } } return (adest); }