1/* 2** Copyright 2001, Travis Geiselbrecht. All rights reserved. 3** Distributed under the terms of the NewOS License. 4*/ 5 6#include <sys/types.h> 7#include <string.h> 8 9 10typedef int word; 11 12#define lsize sizeof(word) 13#define lmask (lsize - 1) 14 15void *memcpy(void *dest, const void *src, size_t count) 16{ 17 char *d = (char *)dest; 18 const char *s = (const char *)src; 19 int len; 20 21 if(count == 0 || dest == src) 22 return dest; 23 24 if(((long)d | (long)s) & lmask) { 25 // src and/or dest do not align on word boundary 26 if((((long)d ^ (long)s) & lmask) || (count < lsize)) 27 len = count; // copy the rest of the buffer with the byte mover 28 else 29 len = lsize - ((long)d & lmask); // move the ptrs up to a word boundary 30 31 count -= len; 32 for(; len > 0; len--) 33 *d++ = *s++; 34 } 35 for(len = count / lsize; len > 0; len--) { 36 *(word *)d = *(word *)s; 37 d += lsize; 38 s += lsize; 39 } 40 for(len = count & lmask; len > 0; len--) 41 *d++ = *s++; 42 43 return dest; 44} 45 46