Xref: utzoo comp.lang.c:22324 comp.unix.questions:16608 comp.unix.wizards:18365 Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!cs.utexas.edu!uunet!mcsun!unido!isaak!kaercher From: kaercher%isaak@isaak.uucp (Michael Kaercher) Newsgroups: comp.lang.c,comp.unix.questions,comp.unix.wizards Subject: Re: Bcopy, bzero and bcmp on a not-Berkeley machine Keywords: bcopy bzero bcmp berkely system_v Message-ID: <1583@isaak.UUCP> Date: 27 Sep 89 13:57:51 GMT References: <1155@radig.UUCP> Sender: news@isaak.UUCP Reply-To: kaercher%isaak@isaak.UUCP (Michael Kaercher) Organization: ISA GmbH, Stuttgart, West-Germany Lines: 41 In article <1155@radig.UUCP> peter@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