bcopy and bzero on AT&T sysV

Karl Heuer karl at haddock.ima.isc.com
Fri Jun 15 11:36:48 AEST 1990


In article <1990Jun14.233837.22318 at virtech.uucp> cpcahil at 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 at ima.ima.isc.com or harvard!ima!karl), The Walking Lint
--------cut here--------

#include <string.h>
/*
 * 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);
}



More information about the Comp.sys.att mailing list