3 * Copyright (C) 2009 Tomas 'ZeXx86' Jedrzejek (zexx86@zexos.org)
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include <string.h> /* size_t */
24 #define lmask (sizeof (long) - 1)
26 void *memmove (void *dest
, void const *src
, size_t count
)
28 char *d
= (char *) dest
;
29 const char *s
= (const char *) src
;
32 if (!count
|| dest
== src
)
35 if ((long) d
< (long) s
) {
36 if (((long) d
| (long) s
) & lmask
) {
37 if ((((long) d
^ (long) s
) & lmask
) || (count
< sizeof (long)))
40 len
= sizeof (long) - ((long) d
& lmask
);
43 for(; len
> 0; len
--)
47 for (len
= count
/ sizeof (long); len
> 0; len
--) {
48 *(word
*) d
= *(word
*) s
;
53 for (len
= count
& lmask
; len
> 0; len
--)
59 if (((long) d
| (long) s
) & lmask
) {
60 if ((((long) d
^ (long) s
) & lmask
) || (count
<= sizeof (long)))
63 len
= ((long) d
& lmask
);
67 for (; len
> 0; len
--)
71 for (len
= count
/ sizeof (long); len
> 0; len
--) {
74 *(word
*) d
= *(word
*) s
;
77 for (len
= count
& lmask
; len
> 0; len
--)