andre@3: #if defined(__sun) && !defined(__SVR4) andre@3: /*- andre@3: * Copyright (c) 1990, 1993 andre@3: * The Regents of the University of California. All rights reserved. andre@3: * andre@3: * This code is derived from software contributed to Berkeley by andre@3: * Chris Torek. andre@3: * andre@3: * Redistribution and use in source and binary forms, with or without andre@3: * modification, are permitted provided that the following conditions andre@3: * are met: andre@3: * 1. Redistributions of source code must retain the above copyright andre@3: * notice, this list of conditions and the following disclaimer. andre@3: * 2. Redistributions in binary form must reproduce the above copyright andre@3: * notice, this list of conditions and the following disclaimer in the andre@3: * documentation and/or other materials provided with the distribution. andre@3: * 3. ***REMOVED*** - see andre@3: * ftp://ftp.cs.berkeley.edu/pub/4bsd/README.Impt.License.Change andre@3: * 4. Neither the name of the University nor the names of its contributors andre@3: * may be used to endorse or promote products derived from this software andre@3: * without specific prior written permission. andre@3: * andre@3: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND andre@3: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE andre@3: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE andre@3: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE andre@3: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL andre@3: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS andre@3: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) andre@3: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT andre@3: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY andre@3: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF andre@3: * SUCH DAMAGE. andre@3: */ andre@3: andre@3: #if defined(LIBC_SCCS) && !defined(lint) andre@3: static char sccsid[] = "@(#)bcopy.c 8.1 (Berkeley) 6/4/93"; andre@3: #endif /* LIBC_SCCS and not lint */ andre@3: andre@3: #ifdef HAVE_SYS_CDEFS_H andre@3: #include andre@3: #else andre@3: #include "cdefs.h" andre@3: #endif andre@3: #include andre@3: andre@3: /* andre@3: * sizeof(word) MUST BE A POWER OF TWO andre@3: * SO THAT wmask BELOW IS ALL ONES andre@3: */ andre@3: typedef int word; /* "word" used for optimal copy speed */ andre@3: andre@3: #define wsize sizeof(word) andre@3: #define wmask (wsize - 1) andre@3: andre@3: /* andre@3: * Copy a block of memory, handling overlap. andre@3: * This is the routine that actually implements andre@3: * (the portable versions of) bcopy, memcpy, and memmove. andre@3: */ andre@3: #ifdef MEMCOPY andre@3: void * andre@3: memcpy(dst0, src0, length) andre@3: #else andre@3: #ifdef MEMMOVE andre@3: void * andre@3: memmove(dst0, src0, length) andre@3: #else andre@3: void andre@3: bcopy(src0, dst0, length) andre@3: #endif andre@3: #endif andre@3: void *dst0; andre@3: const void *src0; andre@3: register size_t length; andre@3: { andre@3: register char *dst = dst0; andre@3: register const char *src = src0; andre@3: register size_t t; andre@3: andre@3: if (length == 0 || dst == src) /* nothing to do */ andre@3: goto done; andre@3: andre@3: /* andre@3: * Macros: loop-t-times; and loop-t-times, t>0 andre@3: */ andre@3: #define TLOOP(s) if (t) TLOOP1(s) andre@3: #define TLOOP1(s) do { s; } while (--t) andre@3: andre@3: if ((unsigned long)dst < (unsigned long)src) { andre@3: /* andre@3: * Copy forward. andre@3: */ andre@3: t = (int)src; /* only need low bits */ andre@3: if ((t | (int)dst) & wmask) { andre@3: /* andre@3: * Try to align operands. This cannot be done andre@3: * unless the low bits match. andre@3: */ andre@3: if ((t ^ (int)dst) & wmask || length < wsize) andre@3: t = length; andre@3: else andre@3: t = wsize - (t & wmask); andre@3: length -= t; andre@3: TLOOP1(*dst++ = *src++); andre@3: } andre@3: /* andre@3: * Copy whole words, then mop up any trailing bytes. andre@3: */ andre@3: t = length / wsize; andre@3: TLOOP(*(word *)dst = *(word *)src; src += wsize; dst += wsize); andre@3: t = length & wmask; andre@3: TLOOP(*dst++ = *src++); andre@3: } else { andre@3: /* andre@3: * Copy backwards. Otherwise essentially the same. andre@3: * Alignment works as before, except that it takes andre@3: * (t&wmask) bytes to align, not wsize-(t&wmask). andre@3: */ andre@3: src += length; andre@3: dst += length; andre@3: t = (int)src; andre@3: if ((t | (int)dst) & wmask) { andre@3: if ((t ^ (int)dst) & wmask || length <= wsize) andre@3: t = length; andre@3: else andre@3: t &= wmask; andre@3: length -= t; andre@3: TLOOP1(*--dst = *--src); andre@3: } andre@3: t = length / wsize; andre@3: TLOOP(src -= wsize; dst -= wsize; *(word *)dst = *(word *)src); andre@3: t = length & wmask; andre@3: TLOOP(*--dst = *--src); andre@3: } andre@3: done: andre@3: #if defined(MEMCOPY) || defined(MEMMOVE) andre@3: return (dst0); andre@3: #else andre@3: return; andre@3: #endif andre@3: } andre@3: #endif /* no __sgi */ andre@3: andre@3: /* Some compilers don't like an empty source file. */ andre@3: static int dummy = 0;