COHERENT manpages

This page displays the COHERENT manpage for memmove() [Copy region of memory into area it overlaps].

List of available manpages
Index


memmove() -- String Function (libc)

Copy region of memory into area it overlaps
#include <string.h>
char *memmove(region1, region2, count)
char *region1, char *region2, unsigned int count;

memmove()  copies  count  characters  from  region2  into  region1.  Unlike
memcpy(), memmove() correctly copies  the region pointed to by region2 into
that pointed by region1 even  if they overlap.  To ``correctly copy'' means
that the overlap  does not propagate, not that the  moved data stay intact.
Unlike  the  string-copying  routines  strcpy()  and  strncpy(),  memmove()
continues to copy even if it encounters a NUL.

memmove() returns region1.

Example

The following example rotates a block of memory by one byte.

#include <string.h>
#include <stddef.h>
#include <stdio.h>

char *
rotate_left(region, len)
char *region; size_t len;
{
    char sav;

    sav = *region;
    /* with memcpy this might propagate the last char */
    memmove(region, region + 1, --len);
    region[len] = sav;
    return(region);
}

char nums[] = "0123456789";
main(void)
{
    printf(rotate_left(nums, strlen(nums)));
    return(EXIT_SUCCESS);
}

See Also

libc,
string.h
ANSI Standard, §7.11.2.2

Notes

region1  should point  to enough  reserved memory to  hold the  contents of
region2. Otherwise, code or data will be overwritten.