ulib dlinklist, string_memmove()
This commit is contained in:
@ -183,3 +183,32 @@ char *string_combine(char *dest, const char *src) {
|
||||
dest[i+j] = '\0';
|
||||
return dest;
|
||||
}
|
||||
|
||||
// https://aticleworld.com/memmove-function-implementation-in-c/
|
||||
void * string_memmove(void* dest, const void* src, unsigned int n)
|
||||
{
|
||||
char *pDest = (char *)dest;
|
||||
const char *pSrc =( const char*)src;
|
||||
//allocate memory for tmp array
|
||||
char *tmp = (char *)umalloc(sizeof(char ) * n);
|
||||
if(NULL == tmp)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
unsigned int i = 0;
|
||||
// copy src to tmp array
|
||||
for(i =0; i < n ; ++i)
|
||||
{
|
||||
*(tmp + i) = *(pSrc + i);
|
||||
}
|
||||
//copy tmp to dest
|
||||
for(i =0 ; i < n ; ++i)
|
||||
{
|
||||
*(pDest + i) = *(tmp + i);
|
||||
}
|
||||
ufree(tmp); //free allocated memory
|
||||
}
|
||||
return dest;
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ char *string_strchr(const char *s, int c);
|
||||
int string_strncmp(const char * s1, const char * s2, size_t n);
|
||||
char *string_tokenizealloc(char *s, char *delim);
|
||||
char *string_combine(char *dest, const char *src);
|
||||
void * string_memmove(void* dest, const void* src, unsigned int n);
|
||||
|
||||
#endif
|
||||
|
||||
|
Reference in New Issue
Block a user