1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/security/nss/lib/dbm/src/memmove.c Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,146 @@ 1.4 +#if defined(__sun) && !defined(__SVR4) 1.5 +/*- 1.6 + * Copyright (c) 1990, 1993 1.7 + * The Regents of the University of California. All rights reserved. 1.8 + * 1.9 + * This code is derived from software contributed to Berkeley by 1.10 + * Chris Torek. 1.11 + * 1.12 + * Redistribution and use in source and binary forms, with or without 1.13 + * modification, are permitted provided that the following conditions 1.14 + * are met: 1.15 + * 1. Redistributions of source code must retain the above copyright 1.16 + * notice, this list of conditions and the following disclaimer. 1.17 + * 2. Redistributions in binary form must reproduce the above copyright 1.18 + * notice, this list of conditions and the following disclaimer in the 1.19 + * documentation and/or other materials provided with the distribution. 1.20 + * 3. ***REMOVED*** - see 1.21 + * ftp://ftp.cs.berkeley.edu/pub/4bsd/README.Impt.License.Change 1.22 + * 4. Neither the name of the University nor the names of its contributors 1.23 + * may be used to endorse or promote products derived from this software 1.24 + * without specific prior written permission. 1.25 + * 1.26 + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 1.27 + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1.28 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1.29 + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 1.30 + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 1.31 + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 1.32 + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 1.33 + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 1.34 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 1.35 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 1.36 + * SUCH DAMAGE. 1.37 + */ 1.38 + 1.39 +#if defined(LIBC_SCCS) && !defined(lint) 1.40 +static char sccsid[] = "@(#)bcopy.c 8.1 (Berkeley) 6/4/93"; 1.41 +#endif /* LIBC_SCCS and not lint */ 1.42 + 1.43 +#ifdef HAVE_SYS_CDEFS_H 1.44 +#include <sys/cdefs.h> 1.45 +#else 1.46 +#include "cdefs.h" 1.47 +#endif 1.48 +#include <string.h> 1.49 + 1.50 +/* 1.51 + * sizeof(word) MUST BE A POWER OF TWO 1.52 + * SO THAT wmask BELOW IS ALL ONES 1.53 + */ 1.54 +typedef int word; /* "word" used for optimal copy speed */ 1.55 + 1.56 +#define wsize sizeof(word) 1.57 +#define wmask (wsize - 1) 1.58 + 1.59 +/* 1.60 + * Copy a block of memory, handling overlap. 1.61 + * This is the routine that actually implements 1.62 + * (the portable versions of) bcopy, memcpy, and memmove. 1.63 + */ 1.64 +#ifdef MEMCOPY 1.65 +void * 1.66 +memcpy(dst0, src0, length) 1.67 +#else 1.68 +#ifdef MEMMOVE 1.69 +void * 1.70 +memmove(dst0, src0, length) 1.71 +#else 1.72 +void 1.73 +bcopy(src0, dst0, length) 1.74 +#endif 1.75 +#endif 1.76 + void *dst0; 1.77 + const void *src0; 1.78 + register size_t length; 1.79 +{ 1.80 + register char *dst = dst0; 1.81 + register const char *src = src0; 1.82 + register size_t t; 1.83 + 1.84 + if (length == 0 || dst == src) /* nothing to do */ 1.85 + goto done; 1.86 + 1.87 + /* 1.88 + * Macros: loop-t-times; and loop-t-times, t>0 1.89 + */ 1.90 +#define TLOOP(s) if (t) TLOOP1(s) 1.91 +#define TLOOP1(s) do { s; } while (--t) 1.92 + 1.93 + if ((unsigned long)dst < (unsigned long)src) { 1.94 + /* 1.95 + * Copy forward. 1.96 + */ 1.97 + t = (int)src; /* only need low bits */ 1.98 + if ((t | (int)dst) & wmask) { 1.99 + /* 1.100 + * Try to align operands. This cannot be done 1.101 + * unless the low bits match. 1.102 + */ 1.103 + if ((t ^ (int)dst) & wmask || length < wsize) 1.104 + t = length; 1.105 + else 1.106 + t = wsize - (t & wmask); 1.107 + length -= t; 1.108 + TLOOP1(*dst++ = *src++); 1.109 + } 1.110 + /* 1.111 + * Copy whole words, then mop up any trailing bytes. 1.112 + */ 1.113 + t = length / wsize; 1.114 + TLOOP(*(word *)dst = *(word *)src; src += wsize; dst += wsize); 1.115 + t = length & wmask; 1.116 + TLOOP(*dst++ = *src++); 1.117 + } else { 1.118 + /* 1.119 + * Copy backwards. Otherwise essentially the same. 1.120 + * Alignment works as before, except that it takes 1.121 + * (t&wmask) bytes to align, not wsize-(t&wmask). 1.122 + */ 1.123 + src += length; 1.124 + dst += length; 1.125 + t = (int)src; 1.126 + if ((t | (int)dst) & wmask) { 1.127 + if ((t ^ (int)dst) & wmask || length <= wsize) 1.128 + t = length; 1.129 + else 1.130 + t &= wmask; 1.131 + length -= t; 1.132 + TLOOP1(*--dst = *--src); 1.133 + } 1.134 + t = length / wsize; 1.135 + TLOOP(src -= wsize; dst -= wsize; *(word *)dst = *(word *)src); 1.136 + t = length & wmask; 1.137 + TLOOP(*--dst = *--src); 1.138 + } 1.139 +done: 1.140 +#if defined(MEMCOPY) || defined(MEMMOVE) 1.141 + return (dst0); 1.142 +#else 1.143 + return; 1.144 +#endif 1.145 +} 1.146 +#endif /* no __sgi */ 1.147 + 1.148 +/* Some compilers don't like an empty source file. */ 1.149 +static int dummy = 0;