File: memmove.c

package info (click to toggle)
saml 970418-3
  • links: PTS
  • area: main
  • in suites: slink
  • size: 1,204 kB
  • ctags: 1,701
  • sloc: ansic: 17,182; sh: 2,583; yacc: 497; perl: 264; makefile: 250; python: 242
file content (35 lines) | stat: -rw-r--r-- 901 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/*
 * SunOS doesn't provide a memmove() function, and you cannot simply put
 * -Dmemmove=memcpy in the Makefiles because memcpy() doesn't support
 * overlapping copies. Oddly enough, bcopy() does! So we can write memmove
 * as a wrapper around bcopy.
 *
 * If you don't have bcopy(), or if it doesn't support overlapping copies,
 * you can still define NO_BCOPY and use the generic version below.
 * It's very slow of course, as it copies only one byte at a time.
 * Complain to your vendor, or get a real Unix.
 */

#ifdef NO_BCOPY
char *memmove (char *dest, char *src, unsigned long count)
{
	char *save_dest = dest;

	if (dest < src) {
		while (count--)
			*dest++ = *src++;
	} else {
		src  += count;
		dest += count;
		while (count--)
			*--dest = *--src;
	}
	return save_dest;
}
#else
char *memmove (char *dest, char *src, unsigned long count)
{
	bcopy(src, dest, count);
	return dest;
}
#endif