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:
parent
d052876f85
commit
1270c767cd
|
@ -134,18 +134,6 @@ localtime (time_t const *timep)
|
|||
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 *
|
||||
memset (void *s, int c, size_t n)
|
||||
{
|
||||
|
|
14
lib/libc.c
14
lib/libc.c
|
@ -294,13 +294,25 @@ memcpy (void *dest, void const *src, size_t n)
|
|||
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 *
|
||||
realloc (void *ptr, size_t size)
|
||||
{
|
||||
void *new = malloc (size);
|
||||
if (ptr && new)
|
||||
{
|
||||
memcpy (new, ptr, size);
|
||||
memmove (new, ptr, size);
|
||||
free (ptr);
|
||||
}
|
||||
return new;
|
||||
|
|
Loading…
Reference in a new issue