mlibc: Use memmove in realloc.

* src/libc.c (memmove): New function.
  (realloc): Use it.
* src/libc+tcc.c (memmove): Remove.
This commit is contained in:
Jan Nieuwenhuizen 2018-04-15 08:13:36 +02:00
parent d052876f85
commit 1270c767cd
No known key found for this signature in database
GPG key ID: F3C1A0D9C1D65273
2 changed files with 13 additions and 13 deletions

View file

@ -134,18 +134,6 @@ localtime (time_t const *timep)
return 0; return 0;
} }
void *
memmove (void *dest, void const *src, size_t n)
{
if (dest < src)
return memcpy (dest, src, n);
char *p = dest + n;
char const *q = src +n;
while (n--)
*--p = *--q;
return dest;
}
void * void *
memset (void *s, int c, size_t n) memset (void *s, int c, size_t n)
{ {

View file

@ -294,13 +294,25 @@ memcpy (void *dest, void const *src, size_t n)
return dest; return dest;
} }
void *
memmove (void *dest, void const *src, size_t n)
{
if (dest < src)
return memcpy (dest, src, n);
char *p = dest + n;
char const *q = src +n;
while (n--)
*--p = *--q;
return dest;
}
void * void *
realloc (void *ptr, size_t size) realloc (void *ptr, size_t size)
{ {
void *new = malloc (size); void *new = malloc (size);
if (ptr && new) if (ptr && new)
{ {
memcpy (new, ptr, size); memmove (new, ptr, size);
free (ptr); free (ptr);
} }
return new; return new;