Path: blob/master/thirdparty/sdl/stdlib/SDL_memmove.c
9903 views
/*1Simple DirectMedia Layer2Copyright (C) 1997-2025 Sam Lantinga <[email protected]>34This software is provided 'as-is', without any express or implied5warranty. In no event will the authors be held liable for any damages6arising from the use of this software.78Permission is granted to anyone to use this software for any purpose,9including commercial applications, and to alter it and redistribute it10freely, subject to the following restrictions:11121. The origin of this software must not be misrepresented; you must not13claim that you wrote the original software. If you use this software14in a product, an acknowledgment in the product documentation would be15appreciated but is not required.162. Altered source versions must be plainly marked as such, and must not be17misrepresented as being the original software.183. This notice may not be removed or altered from any source distribution.19*/20#include "SDL_internal.h"212223#ifdef SDL_memmove24#undef SDL_memmove25#endif26#if SDL_DYNAMIC_API27#define SDL_memmove SDL_memmove_REAL28#endif29void *SDL_memmove(SDL_OUT_BYTECAP(len) void *dst, SDL_IN_BYTECAP(len) const void *src, size_t len)30{31#if defined(__GNUC__) && (defined(HAVE_LIBC) && HAVE_LIBC)32// Presumably this is well tuned for speed.33return __builtin_memmove(dst, src, len);34#elif defined(HAVE_MEMMOVE)35return memmove(dst, src, len);36#else37char *srcp = (char *)src;38char *dstp = (char *)dst;3940if (src < dst) {41srcp += len - 1;42dstp += len - 1;43while (len--) {44*dstp-- = *srcp--;45}46} else {47while (len--) {48*dstp++ = *srcp++;49}50}51return dst;52#endif // HAVE_MEMMOVE53}545556#ifndef HAVE_LIBC57// NOLINTNEXTLINE(readability-redundant-declaration)58extern void *memmove(void *dst, const void *src, size_t len);59#if defined(_MSC_VER) && !defined(__INTEL_LLVM_COMPILER)60#pragma intrinsic(memmove)61#endif6263#if defined(_MSC_VER) && !defined(__clang__)64#pragma function(memmove)65#endif66// NOLINTNEXTLINE(readability-inconsistent-declaration-parameter-name)67void *memmove(void *dst, const void *src, size_t len)68{69return SDL_memmove(dst, src, len);70}71#endif // !HAVE_LIBC72737475