Cleanup in elf.c with .bss section clean; adm command mounts cdrom instead of floppy...
[ZeXOS.git] / libc / string / memmove.c
blobdab62b46a8ac0ec7d51835921eb24300fb818af5
1 /*
2 * ZeX/OS
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 */
22 typedef long word;
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;
30 int len;
32 if (!count || dest == src)
33 return dest;
35 if ((long) d < (long) s) {
36 if (((long) d | (long) s) & lmask) {
37 if ((((long) d ^ (long) s) & lmask) || (count < sizeof (long)))
38 len = count;
39 else
40 len = sizeof (long) - ((long) d & lmask);
42 count -= len;
43 for(; len > 0; len --)
44 *d ++ = *s ++;
47 for (len = count / sizeof (long); len > 0; len --) {
48 *(word *) d = *(word *) s;
49 d += sizeof (long);
50 s += sizeof (long);
53 for (len = count & lmask; len > 0; len --)
54 *d ++ = *s ++;
55 } else {
56 d += count;
57 s += count;
59 if (((long) d | (long) s) & lmask) {
60 if ((((long) d ^ (long) s) & lmask) || (count <= sizeof (long)))
61 len = count;
62 else
63 len = ((long) d & lmask);
65 count -= len;
67 for (; len > 0; len --)
68 *-- d = *-- s;
71 for (len = count / sizeof (long); len > 0; len --) {
72 d -= sizeof (long);
73 s -= sizeof (long);
74 *(word *) d = *(word *) s;
77 for (len = count & lmask; len > 0; len --)
78 *-- d = *-- s;
81 return dest;