Hackfix and re-enable strtoull and wcstoull, see bug #3798.
[sdcc.git] / sdcc / device / lib / _memmove.c
blobff42456428eeb8ea17865169f4c9bece73e7ca97
1 /*-------------------------------------------------------------------------
2 _memmove.c - part of string library functions
4 Copyright (C) 1999, Sandeep Dutta . sandeep.dutta@usa.net
5 Copyright (C) 2022, Sebastian 'basxto' Riedel . sdcc@basxto.de
6 Adapted By - Erik Petrich . epetrich@users.sourceforge.net
7 from _memcpy.c which was originally
9 This library is free software; you can redistribute it and/or modify it
10 under the terms of the GNU General Public License as published by the
11 Free Software Foundation; either version 2, or (at your option) any
12 later version.
14 This library is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this library; see the file COPYING. If not, write to the
21 Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
22 MA 02110-1301, USA.
24 As a special exception, if you link this library with other files,
25 some of which are compiled with SDCC, to produce an executable,
26 this library does not by itself cause the resulting executable to
27 be covered by the GNU General Public License. This exception does
28 not however invalidate any other reasons why the executable file
29 might be covered by the GNU General Public License.
30 -------------------------------------------------------------------------*/
31 #include <string.h>
32 #include <stdint.h>
33 #include <sdcc-lib.h>
35 void *memmove (void *dst, const void *src, size_t size)
37 size_t c = size;
38 if (c == 0 || dst == src)
39 return dst;
41 char *d = dst;
42 const char *s = src;
43 if (s < d) {
44 #if !defined (_SDCC_NO_ASM_LIB_FUNCS) && defined(__SDCC_sm83)
45 if (s + c < d) { // no overlap
46 // sm83 asm memcpy copies ascending (and faster than this)
47 return memcpy(d, s, c);
49 #endif
50 s += c;
51 d += c;
52 do {
53 *--d = *--s;
54 } while (--c);
55 } else {
56 #if !defined (_SDCC_NO_ASM_LIB_FUNCS) && defined(__SDCC_sm83)
57 return memcpy(d, s, c);
58 #else
59 do {
60 *d++ = *s++;
61 } while (--c);
62 #endif
65 return dst;