C Programming/C Reference/nonstandard/mempcpy

The C language function calls mempcpy and wmempcpy are used to copy one area of memory to another area.

Introduction
In C, the function mempcpy is included in header file string.h. mempcpy is nearly identical to memcpy. This function is used to copy the strings. The function wmempcpy is identical to mempcpy but takes wchar_t type arguments and copies n wide characters. It comes under wchar.h header file.

Description
In C programming, functions mempcpy, wmempcpy are used.The mempcpy function is nearly identical to the memcpy function.It comes under Buffer Manipulating Functions. It copies a specified number of characters from one buffer to another. It copies n bytes from the object beginning at  src  into  the  object pointed to  by  dest. But instead of returning the value of dest it returns a pointer to the byte following the last written byte. This function is useful in situations where a number of objects  shall be copied to consecutive memory positions. If copying between objects overlap, then the behavior is undefined.

Return value
dest + n.

Example
void *

combine (ciod *o1, size_t s1, void *o2, size_t s2)

{

void *result = malloc(s1 + s2);

if (result != NULL)

mempcpy(mempcpy(result, o1, s1), o2, s2);

return result;

}

Versions
mempcpy first appeared in glibc in version 2.1