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