Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | #if defined(__sun) && !defined(__SVR4) |
michael@0 | 2 | /*- |
michael@0 | 3 | * Copyright (c) 1990, 1993 |
michael@0 | 4 | * The Regents of the University of California. All rights reserved. |
michael@0 | 5 | * |
michael@0 | 6 | * This code is derived from software contributed to Berkeley by |
michael@0 | 7 | * Chris Torek. |
michael@0 | 8 | * |
michael@0 | 9 | * Redistribution and use in source and binary forms, with or without |
michael@0 | 10 | * modification, are permitted provided that the following conditions |
michael@0 | 11 | * are met: |
michael@0 | 12 | * 1. Redistributions of source code must retain the above copyright |
michael@0 | 13 | * notice, this list of conditions and the following disclaimer. |
michael@0 | 14 | * 2. Redistributions in binary form must reproduce the above copyright |
michael@0 | 15 | * notice, this list of conditions and the following disclaimer in the |
michael@0 | 16 | * documentation and/or other materials provided with the distribution. |
michael@0 | 17 | * 3. ***REMOVED*** - see |
michael@0 | 18 | * ftp://ftp.cs.berkeley.edu/pub/4bsd/README.Impt.License.Change |
michael@0 | 19 | * 4. Neither the name of the University nor the names of its contributors |
michael@0 | 20 | * may be used to endorse or promote products derived from this software |
michael@0 | 21 | * without specific prior written permission. |
michael@0 | 22 | * |
michael@0 | 23 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND |
michael@0 | 24 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
michael@0 | 25 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
michael@0 | 26 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
michael@0 | 27 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
michael@0 | 28 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
michael@0 | 29 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
michael@0 | 30 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
michael@0 | 31 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
michael@0 | 32 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
michael@0 | 33 | * SUCH DAMAGE. |
michael@0 | 34 | */ |
michael@0 | 35 | |
michael@0 | 36 | #if defined(LIBC_SCCS) && !defined(lint) |
michael@0 | 37 | static char sccsid[] = "@(#)bcopy.c 8.1 (Berkeley) 6/4/93"; |
michael@0 | 38 | #endif /* LIBC_SCCS and not lint */ |
michael@0 | 39 | |
michael@0 | 40 | #ifdef HAVE_SYS_CDEFS_H |
michael@0 | 41 | #include <sys/cdefs.h> |
michael@0 | 42 | #else |
michael@0 | 43 | #include "cdefs.h" |
michael@0 | 44 | #endif |
michael@0 | 45 | #include <string.h> |
michael@0 | 46 | |
michael@0 | 47 | /* |
michael@0 | 48 | * sizeof(word) MUST BE A POWER OF TWO |
michael@0 | 49 | * SO THAT wmask BELOW IS ALL ONES |
michael@0 | 50 | */ |
michael@0 | 51 | typedef int word; /* "word" used for optimal copy speed */ |
michael@0 | 52 | |
michael@0 | 53 | #define wsize sizeof(word) |
michael@0 | 54 | #define wmask (wsize - 1) |
michael@0 | 55 | |
michael@0 | 56 | /* |
michael@0 | 57 | * Copy a block of memory, handling overlap. |
michael@0 | 58 | * This is the routine that actually implements |
michael@0 | 59 | * (the portable versions of) bcopy, memcpy, and memmove. |
michael@0 | 60 | */ |
michael@0 | 61 | #ifdef MEMCOPY |
michael@0 | 62 | void * |
michael@0 | 63 | memcpy(dst0, src0, length) |
michael@0 | 64 | #else |
michael@0 | 65 | #ifdef MEMMOVE |
michael@0 | 66 | void * |
michael@0 | 67 | memmove(dst0, src0, length) |
michael@0 | 68 | #else |
michael@0 | 69 | void |
michael@0 | 70 | bcopy(src0, dst0, length) |
michael@0 | 71 | #endif |
michael@0 | 72 | #endif |
michael@0 | 73 | void *dst0; |
michael@0 | 74 | const void *src0; |
michael@0 | 75 | register size_t length; |
michael@0 | 76 | { |
michael@0 | 77 | register char *dst = dst0; |
michael@0 | 78 | register const char *src = src0; |
michael@0 | 79 | register size_t t; |
michael@0 | 80 | |
michael@0 | 81 | if (length == 0 || dst == src) /* nothing to do */ |
michael@0 | 82 | goto done; |
michael@0 | 83 | |
michael@0 | 84 | /* |
michael@0 | 85 | * Macros: loop-t-times; and loop-t-times, t>0 |
michael@0 | 86 | */ |
michael@0 | 87 | #define TLOOP(s) if (t) TLOOP1(s) |
michael@0 | 88 | #define TLOOP1(s) do { s; } while (--t) |
michael@0 | 89 | |
michael@0 | 90 | if ((unsigned long)dst < (unsigned long)src) { |
michael@0 | 91 | /* |
michael@0 | 92 | * Copy forward. |
michael@0 | 93 | */ |
michael@0 | 94 | t = (int)src; /* only need low bits */ |
michael@0 | 95 | if ((t | (int)dst) & wmask) { |
michael@0 | 96 | /* |
michael@0 | 97 | * Try to align operands. This cannot be done |
michael@0 | 98 | * unless the low bits match. |
michael@0 | 99 | */ |
michael@0 | 100 | if ((t ^ (int)dst) & wmask || length < wsize) |
michael@0 | 101 | t = length; |
michael@0 | 102 | else |
michael@0 | 103 | t = wsize - (t & wmask); |
michael@0 | 104 | length -= t; |
michael@0 | 105 | TLOOP1(*dst++ = *src++); |
michael@0 | 106 | } |
michael@0 | 107 | /* |
michael@0 | 108 | * Copy whole words, then mop up any trailing bytes. |
michael@0 | 109 | */ |
michael@0 | 110 | t = length / wsize; |
michael@0 | 111 | TLOOP(*(word *)dst = *(word *)src; src += wsize; dst += wsize); |
michael@0 | 112 | t = length & wmask; |
michael@0 | 113 | TLOOP(*dst++ = *src++); |
michael@0 | 114 | } else { |
michael@0 | 115 | /* |
michael@0 | 116 | * Copy backwards. Otherwise essentially the same. |
michael@0 | 117 | * Alignment works as before, except that it takes |
michael@0 | 118 | * (t&wmask) bytes to align, not wsize-(t&wmask). |
michael@0 | 119 | */ |
michael@0 | 120 | src += length; |
michael@0 | 121 | dst += length; |
michael@0 | 122 | t = (int)src; |
michael@0 | 123 | if ((t | (int)dst) & wmask) { |
michael@0 | 124 | if ((t ^ (int)dst) & wmask || length <= wsize) |
michael@0 | 125 | t = length; |
michael@0 | 126 | else |
michael@0 | 127 | t &= wmask; |
michael@0 | 128 | length -= t; |
michael@0 | 129 | TLOOP1(*--dst = *--src); |
michael@0 | 130 | } |
michael@0 | 131 | t = length / wsize; |
michael@0 | 132 | TLOOP(src -= wsize; dst -= wsize; *(word *)dst = *(word *)src); |
michael@0 | 133 | t = length & wmask; |
michael@0 | 134 | TLOOP(*--dst = *--src); |
michael@0 | 135 | } |
michael@0 | 136 | done: |
michael@0 | 137 | #if defined(MEMCOPY) || defined(MEMMOVE) |
michael@0 | 138 | return (dst0); |
michael@0 | 139 | #else |
michael@0 | 140 | return; |
michael@0 | 141 | #endif |
michael@0 | 142 | } |
michael@0 | 143 | #endif /* no __sgi */ |
michael@0 | 144 | |
michael@0 | 145 | /* Some compilers don't like an empty source file. */ |
michael@0 | 146 | static int dummy = 0; |