On Tue, 19 Aug 2008, [EMAIL PROTECTED] wrote:
[snip]
void *memcpy(void *dst, const void *src, size_t n)
{
- int i, j;
+ int i;
- if (((long)dst & (sizeof(long) - 1))
- || ((long)src & (sizeof(long) - 1)))
- return unaligned_memcpy(dst, src, n);
+ for(i = 0; i < n % sizeof(unsigned long); i++)
+ ((unsigned char *) dst)[i] = ((unsigned char *) src)[i];
- for (i = 0; i < n / sizeof(unsigned long); i++)
- ((unsigned long *)dst)[i] = ((unsigned long *)src)[i];
+ n -= i;
+ src += i;
+ dst += i;
- for (j = 0; j < n % sizeof(unsigned long); j++)
- ((unsigned char *)(((unsigned long *)dst) + i))[j] =
- ((unsigned char *)(((unsigned long *)src) + i))[j];
+ for(i = 0; i < n / sizeof(unsigned long); i++)
+ ((unsigned long *) dst)[i] = ((unsigned long *) src)[i];
- return (char *)src;
+ return dst;
}
Does this really return the correct value?
When I read the Linux memcpy(3) man page and the GNU C library reference
manual I get the impression that the return value should be the original
value of dst. This implementation returns a value which is original dst+0,
1, 2, or 3, depending on n % sizeof(unsigned long).
/ulf
--
coreboot mailing list
[email protected]
http://www.coreboot.org/mailman/listinfo/coreboot