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

edit

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

edit

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

edit

dest + n.

Example

edit

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

edit

mempcpy first appeared in glibc in version 2.1

See also

edit

memccpy( ), memcpy( )

References

edit