source: trunk/sys/dietlibc/memcpy.c @ 392

Last change on this file since 392 was 1, checked in by alain, 7 years ago

First import

File size: 1.1 KB
Line 
1/* fast memcpy -- Copyright (C) 2003 Thomas M. Ogrisegg <tom@hi-tek.fnord.at> */
2
3#include <string.h>
4#include "dietfeatures.h"
5#include "dietstring.h"
6
7void *
8memcpy (void *dst, const void *src, size_t n)
9{
10    void           *res = dst;
11    unsigned char  *c1, *c2;
12#ifdef WANT_SMALL_STRING_ROUTINES
13    c1 = (unsigned char *) dst;
14    c2 = (unsigned char *) src;
15    while (n--) *c1++ = *c2++;
16    return (res);
17#else
18    int             tmp;
19    unsigned long  *lx1 = NULL;
20    const unsigned long *lx2 = NULL;
21
22    if (!UNALIGNED(dst, src) && n > sizeof(unsigned long)) {
23
24        if ((tmp = STRALIGN(dst))) {
25            c1 = (unsigned char *) dst;
26            c2 = (unsigned char *) src;
27            while (tmp-- && n--)
28                *c1++ = *c2++;
29            if (n == (size_t) - 1)
30                return (res);
31            dst = c1;
32            src = c2;
33        }
34
35        lx1 = (unsigned long *) dst;
36        lx2 = (unsigned long *) src;
37
38        for (; n >= sizeof(unsigned long); n -= sizeof(unsigned long))
39            *lx1++ = *lx2++;
40    }
41
42    if (n) {
43        c1 = (unsigned char *) (lx1?lx1:dst);
44        c2 = (unsigned char *) (lx1?lx2:src);
45        while (n--)
46            *c1++ = *c2++;
47    }
48
49    return (res);
50#endif
51}
Note: See TracBrowser for help on using the repository browser.