Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/thirdparty/sdl/stdlib/SDL_memmove.c
9903 views
1
/*
2
Simple DirectMedia Layer
3
Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
4
5
This software is provided 'as-is', without any express or implied
6
warranty. In no event will the authors be held liable for any damages
7
arising from the use of this software.
8
9
Permission is granted to anyone to use this software for any purpose,
10
including commercial applications, and to alter it and redistribute it
11
freely, subject to the following restrictions:
12
13
1. The origin of this software must not be misrepresented; you must not
14
claim that you wrote the original software. If you use this software
15
in a product, an acknowledgment in the product documentation would be
16
appreciated but is not required.
17
2. Altered source versions must be plainly marked as such, and must not be
18
misrepresented as being the original software.
19
3. This notice may not be removed or altered from any source distribution.
20
*/
21
#include "SDL_internal.h"
22
23
24
#ifdef SDL_memmove
25
#undef SDL_memmove
26
#endif
27
#if SDL_DYNAMIC_API
28
#define SDL_memmove SDL_memmove_REAL
29
#endif
30
void *SDL_memmove(SDL_OUT_BYTECAP(len) void *dst, SDL_IN_BYTECAP(len) const void *src, size_t len)
31
{
32
#if defined(__GNUC__) && (defined(HAVE_LIBC) && HAVE_LIBC)
33
// Presumably this is well tuned for speed.
34
return __builtin_memmove(dst, src, len);
35
#elif defined(HAVE_MEMMOVE)
36
return memmove(dst, src, len);
37
#else
38
char *srcp = (char *)src;
39
char *dstp = (char *)dst;
40
41
if (src < dst) {
42
srcp += len - 1;
43
dstp += len - 1;
44
while (len--) {
45
*dstp-- = *srcp--;
46
}
47
} else {
48
while (len--) {
49
*dstp++ = *srcp++;
50
}
51
}
52
return dst;
53
#endif // HAVE_MEMMOVE
54
}
55
56
57
#ifndef HAVE_LIBC
58
// NOLINTNEXTLINE(readability-redundant-declaration)
59
extern void *memmove(void *dst, const void *src, size_t len);
60
#if defined(_MSC_VER) && !defined(__INTEL_LLVM_COMPILER)
61
#pragma intrinsic(memmove)
62
#endif
63
64
#if defined(_MSC_VER) && !defined(__clang__)
65
#pragma function(memmove)
66
#endif
67
// NOLINTNEXTLINE(readability-inconsistent-declaration-parameter-name)
68
void *memmove(void *dst, const void *src, size_t len)
69
{
70
return SDL_memmove(dst, src, len);
71
}
72
#endif // !HAVE_LIBC
73
74
75