Add assertions.
[gnulib.git] / lib / memcpy.c
1 /* Copy LEN bytes starting at SRCADDR to DESTADDR.  Result undefined
2    if the source overlaps with the destination.
3    Return DESTADDR. */
4
5 #include <assert.h>
6
7 /* FIXME: uncomment the following for releases.  */
8 #define NDEBUG 1
9
10 #ifndef ABS
11 # define ABS(x) ((x) < 0 ? (-(x)) : (x))
12 #endif
13
14 char *
15 memcpy (destaddr, srcaddr, len)
16      char *destaddr;
17      const char *srcaddr;
18      int len;
19 {
20   char *dest = destaddr;
21
22   assert (len >= 0);
23   /* Make sure they don't overlap.  */
24   assert (ABS (destaddr - srcaddr) >= len);
25
26   while (len-- > 0)
27     *destaddr++ = *srcaddr++;
28   return dest;
29 }