Bcopy, bzero and bcmp on a not-Berkeley machine
Michael Kaercher
kaercher%isaak at isaak.uucp
Wed Sep 27 23:57:51 AEST 1989
In article <1155 at radig.UUCP> peter at radig.UUCP (Peter Radig) writes:
>Is is possible to replace calls to `bcopy', `bzero' and `bcmp' by
>the following macros:
>
> #ifdef USG
> #define bcmp(s1,s2,cnt) memcpy(s1,s2,cnt)
^^^^^^ This should be memcmp!
> #define bcopy(fr,to,cnt) memcpy(to,fr,cnt)
> #define bzero(addr,cnt) memset(addr,'\0',cnt)
> #endif USG
There may be a big surprise when using these definitions! bcopy does
handle overlapping memory areas correctly whereas memcpy is usually *not*
implemented this way. In case you are porting to Microsoft C: there is a
function in the runtime library called 'memmove' which does handle over-
lapping regions properly.
You can check out whether your definitions are proper with a little
program similar to the following:
main()
{
static char abc[] = "abcdefghi";
static char buffer[50];
strcpy (buffer, abc);
bcopy (buffer, buffer + 1, sizeof(abc));
puts (buffer);
strcpy (buffer, abc);
bcopy (buffer + 1, buffer, sizeof(abc));
puts (buffer);
}
You should get: 'aabcd...' and 'bbcde...'. If the first line of output
shows up as 'aaaaaa...', bcopy (or the program above(?)) is borken...
BTW, i suppose that this feature in bcopy is due to the VAX MOVC3 instruction
Hope this helps,
Michael
More information about the Comp.unix.wizards
mailing list