tholm@uvicctr.UUCP (Terrence W. Holm) (09/14/88)
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 <vector1> X is equal to the data pointed to by <vector2>. Up to X <count> bytes are compared. X XRESULTS X =0 : <vector1> is equal to <vector2> X <>0 : <vector1> is not equal to <vector2> 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 <count> bytes are copied from the memory pointed to X by <from> to the memory pointed to by <to>. If the X location <to> is within the <from> vector, then X the copy is done backwards to save the <from> 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 <count> bytes of <vector> 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