Path: utzoo!utgpu!water!watmath!clyde!att!rutgers!mit-eddie!uw-beaver!ssc-vax!uvicctr!tholm From: tholm@uvicctr.UUCP (Terrence W. Holm) Newsgroups: comp.os.minix Subject: bcopy(3) & friends Message-ID: <497@uvicctr.UUCP> Date: 14 Sep 88 01:16:57 GMT Reply-To: tholm@uvicctr.UUCP (Terrence W. Holm) Organization: University of Victoria, Victoria B.C. Canada Lines: 170 EFTH MINIX report #41 - September 1988 - bcopy(3) & friends There follows an implementation of bcopy(3), bcmp(3) and bzero(3) for MINIX. Please consider this public domain software. "man" pages are included. Note: This replaces the old MINIX bcopy(3) routine. ---------------------------------------------------------- echo x - bcmp.3 gres '^X' '' > bcmp.3 << '/' XSUBROUTINES X bcmp(3) - byte compare X XINVOCATION X int bcmp( vector1, vector2, count ) X char *vector1; X char *vector2; X int count; X XEXPLANATION X Bcmp(3) determines if the data pointed to by X is equal to the data pointed to by . Up to X bytes are compared. X XRESULTS X =0 : is equal to X <>0 : is not equal to X XREFERENCES X memcmp(3), strcmp(3) / echo x - bcmp.c gres '^X' '' > bcmp.c << '/' X/* bcmp(3) X * X * Author: Terrence W. Holm Sep. 1988 X */ X X Xint bcmp( vector1, vector2, count ) X char *vector1; X char *vector2; X int count; X X { X int word_count = count / sizeof(int); X int byte_count = count & ( sizeof(int) - 1 ); X X if ( vector1 == vector2 ) X return( 0 ); X X while( --word_count >= 0 ) X if ( *((int *) vector1)++ != *((int *) vector2)++ ) X return( 1 ); X X while( --byte_count >= 0 ) X if ( *vector1++ != *vector2++ ) X return( 1 ); X X return( 0 ); X } / echo x - bcopy.3 gres '^X' '' > bcopy.3 << '/' XSUBROUTINES X bcopy(3) - byte copy X XINVOCATION X bcopy( from, to, count ) X char *from; X char *to; X int count; X XEXPLANATION X bytes are copied from the memory pointed to X by to the memory pointed to by . If the X location is within the vector, then X the copy is done backwards to save the vector X from being trampled. X XREFERENCES X memcpy(3), strcpy(3) / echo x - bcopy.c gres '^X' '' > bcopy.c << '/' X/* bcopy(3) X * X * Author: Terrence W. Holm Sep. 1988 X */ X X Xbcopy( from, to, count ) X char *from; X char *to; X int count; X X { X int word_count = count / sizeof(int); X int byte_count = count & ( sizeof(int) - 1 ); X X if ( to > from && to < from + count ) X { X /* Must copy backwards */ X from += count; X to += count; X X while( --byte_count >= 0 ) X *--to = *--from; X X while( --word_count >= 0 ) X *--((int *) to) = *--((int *) from); X } X else X { X while( --word_count >= 0 ) X *((int *) to)++ = *((int *) from)++; X X while( --byte_count >= 0 ) X *to++ = *from++; X } X } / echo x - bzero.3 gres '^X' '' > bzero.3 << '/' XSUBROUTINES X bzero(3) - zero a byte string X XINVOCATION X bzero( vector, count ) X char *vector; X int count; X XEXPLANATION X The first bytes of are set to 0. X XREFERENCES X memset(3) / echo x - bzero.c gres '^X' '' > bzero.c << '/' X/* bzero(3) X * X * Author: Terrence W. Holm Sep. 1988 X */ X X Xbzero( vector, count ) X char *vector; X int count; X X { X int word_count = count / sizeof(int); X int byte_count = count & ( sizeof(int) - 1 ); X X while( --word_count >= 0 ) X *((int *) vector)++ = 0; X X while( --byte_count >= 0 ) X *vector++ = 0; X } / ---------------------------------------------------------- Edwin L. Froese uw-beaver!ubc-cs!mprg!handel!froese Terrence W. Holm uw-beaver!uvicctr!tholm