From 7a5099b1d80b13fe971465de78da535902655c85 Mon Sep 17 00:00:00 2001 From: jshepher <> Date: Sat, 11 Dec 2004 18:17:15 +0000 Subject: [PATCH] Allow for overlapping regions. --- libnix/sources/nix/misc/bcopy.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/libnix/sources/nix/misc/bcopy.c b/libnix/sources/nix/misc/bcopy.c index 9339ace..9f8364b 100755 --- a/libnix/sources/nix/misc/bcopy.c +++ b/libnix/sources/nix/misc/bcopy.c @@ -5,8 +5,17 @@ void bcopy(const void *s1,void *s2,size_t n) { unsigned char *ch1 = s1; unsigned char *ch2 = s2; - while (n > 0) { - *ch2++ = *ch1++; - n--; + if (ch1 < ch2) { + while (n > 0) { + *ch2++ = *ch1++; + n--; + } + } else { + ch1 += n; + ch2 += n; + while (n > 0) { + *ch2-- = *ch1--; + n--; + } } }