2003-03-19 23:09:16 +01:00
|
|
|
/*
|
|
|
|
* memmove function
|
|
|
|
*
|
|
|
|
* Copyright 1996 Alexandre Julliard
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2003-03-19 23:09:16 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include "wine/port.h"
|
|
|
|
|
|
|
|
#ifndef HAVE_MEMMOVE
|
2006-08-01 19:35:52 +02:00
|
|
|
void *memmove( void *dest, const void *source, size_t len )
|
2003-03-19 23:09:16 +01:00
|
|
|
{
|
|
|
|
register char *dst = dest;
|
2006-08-01 19:35:52 +02:00
|
|
|
register const char *src = source;
|
2003-03-19 23:09:16 +01:00
|
|
|
|
|
|
|
/* Use memcpy if not overlapping */
|
2006-08-01 19:35:52 +02:00
|
|
|
if ((dst + len <= src) || (src + len <= dst))
|
2003-03-19 23:09:16 +01:00
|
|
|
{
|
|
|
|
memcpy( dst, src, len );
|
|
|
|
}
|
|
|
|
/* Otherwise do it the hard way (FIXME: could do better than this) */
|
2006-08-01 19:35:52 +02:00
|
|
|
else if (dst < src)
|
2003-03-19 23:09:16 +01:00
|
|
|
{
|
2006-08-01 19:35:52 +02:00
|
|
|
while (len--) *dst++ = *src++;
|
2003-03-19 23:09:16 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
dst += len - 1;
|
2006-08-01 19:35:52 +02:00
|
|
|
src += len - 1;
|
|
|
|
while (len--) *dst-- = *src--;
|
2003-03-19 23:09:16 +01:00
|
|
|
}
|
|
|
|
return dest;
|
|
|
|
}
|
|
|
|
#endif /* HAVE_MEMMOVE */
|