bcopy.c 640 Bytes
Newer Older
Jim Meyering's avatar
Jim Meyering committed
1 2 3 4 5
/* bcopy.c -- copy memory.
   Copy LENGTH bytes from SOURCE to DEST.  Does not null-terminate.
   In the public domain.
   By David MacKenzie <djm@gnu.ai.mit.edu>.  */

6 7
#include <config.h>

Paul Eggert's avatar
Paul Eggert committed
8 9
#include <stddef.h>

Jim Meyering's avatar
Jim Meyering committed
10
void
Paul Eggert's avatar
Paul Eggert committed
11
bcopy (void const *source0, void *dest0, size_t length)
Jim Meyering's avatar
Jim Meyering committed
12
{
Paul Eggert's avatar
Paul Eggert committed
13 14
  char const *source = source0;
  char *dest = dest0;
Jim Meyering's avatar
Jim Meyering committed
15 16 17 18 19 20 21 22 23
  if (source < dest)
    /* Moving from low mem to hi mem; start at end.  */
    for (source += length, dest += length; length; --length)
      *--dest = *--source;
  else if (source != dest)
    /* Moving from hi mem to low mem; start at beginning.  */
    for (; length; --length)
      *dest++ = *source++;
}