1 /** 2 * Part of the D programming language runtime library. 3 */ 4 5 /* 6 * Copyright (C) 2004-2007 by Digital Mars, www.digitalmars.com 7 * Written by Walter Bright 8 * 9 * This software is provided 'as-is', without any express or implied 10 * warranty. In no event will the authors be held liable for any damages 11 * arising from the use of this software. 12 * 13 * Permission is granted to anyone to use this software for any purpose, 14 * including commercial applications, and to alter it and redistribute it 15 * freely, in both source and binary form, subject to the following 16 * restrictions: 17 * 18 * o The origin of this software must not be misrepresented; you must not 19 * claim that you wrote the original software. If you use this software 20 * in a product, an acknowledgment in the product documentation would be 21 * appreciated but is not required. 22 * o Altered source versions must be plainly marked as such, and must not 23 * be misrepresented as being the original software. 24 * o This notice may not be removed or altered from any source 25 * distribution. 26 */ 27 28 /* 29 * Modified by Sean Kelly <sean@f4.ca> for use with Tango. 30 */ 31 module rt.compiler.gdc.rt.arraycat; 32 private 33 { 34 import tango.stdc.string; 35 debug(ARRAY_COPY) import tango.stdc.stdio; 36 } 37 38 extern (C): 39 40 byte[] _d_arraycopy(size_t size, byte[] from, byte[] to) 41 { 42 debug(ARRAY_COPY) printf("f = %p,%d, t = %p,%d, size = %d\n", 43 from.ptr, from.length, to.ptr, to.length, size); 44 45 if (to.length != from.length) 46 { 47 throw new Exception("lengths don't match for array copy"); 48 } 49 else if (to.ptr + to.length * size <= from.ptr || 50 from.ptr + from.length * size <= to.ptr) 51 { 52 memcpy(to.ptr, from.ptr, to.length * size); 53 } 54 else 55 { 56 throw new Exception("overlapping array copy"); 57 } 58 return to; 59 }