Path: utzoo!attcan!uunet!husc6!ogccse!blake!uw-beaver!ssc-vax!uvicctr!tholm From: tholm@uvicctr.UUCP (Terrence W. Holm) Newsgroups: comp.os.minix Subject: memcpy(3), etc. for MINIX-ST Message-ID: <553@uvicctr.UUCP> Date: 22 Nov 88 21:34:08 GMT Reply-To: tholm@uvicctr.UUCP (Terrence W. Holm) Organization: University of Victoria, Victoria B.C. Canada Lines: 208 EFTH MINIX report #59 - November 1988 - memcpy(3), etc. for MINIX-ST My previous posting of memcpy(3), etc. could copy int's at an odd address. This does not work on an MC68000 system. The following fixes the problem, (and also runs faster on 80286 machines when the data is word aligned). ---------------------------------------------------------- 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 register char *vector1; X register char *vector2; X int count; X X { X register int long_count; X register int byte_count; X X if ( vector1 == vector2 ) X return( 0 ); X X /* Only compare longs if both are on an */ X /* even byte boundary. */ X X if ( ((int) vector1 & 1) || ((int) vector2 & 1) ) X { X long_count = 0; X byte_count = count; X } X else X { X long_count = count >> 2; /* Assumes sizeof(long) is 4 */ X byte_count = count & 03; X } X X X while( --long_count >= 0 ) X if ( *((long *) vector1)++ != *((long *) 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.c gres '^X' '' > bcopy.c << '/' X/* bcopy(3) X * X * Author: Terrence W. Holm Sep. 1988 X */ X X Xbcopy( from, to, count ) X register char *from; X register char *to; X int count; X X { X register int long_count; X register int byte_count; X X /* Only copy longs if both source and destination */ X /* are on an even byte boundary. */ X X if ( ((int) to & 1) || ((int) from & 1) ) X { X long_count = 0; X byte_count = count; X } X else X { X long_count = count >> 2; /* Assumes sizeof(long) is 4 */ X byte_count = count & 03; X } X 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( --long_count >= 0 ) X *--((long *) to) = *--((long *) from); X } X else X { X while( --long_count >= 0 ) X *((long *) to)++ = *((long *) from)++; X X while( --byte_count >= 0 ) X *to++ = *from++; X } X } / 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 register char *vector; X int count; X X { X register int long_count; X register int byte_count; X X /* Only use longs if on an even byte boundary */ X X if ( (int) vector & 1 ) X { X long_count = 0; X byte_count = count; X } X else X { X long_count = count >> 2; /* Assumes sizeof(long) is 4 */ X byte_count = count & 03; X } X X while( --long_count >= 0 ) X *((long *) vector)++ = 0L; X X while( --byte_count >= 0 ) X *vector++ = 0; X } / echo x - memcpy.c gres '^X' '' > memcpy.c << '/' X/* memcpy(3) X * X * Author: Terrence W. Holm Sep. 1988 X */ X X Xchar *memcpy( to, from, count ) X register char *to; X register char *from; X int count; X X { X char *temp_to = to; X register int long_count; X register int byte_count; X X /* Only copy longs if both source and destination */ X /* are on an even byte boundary. */ X X if ( ((int) to & 1) || ((int) from & 1) ) X { X long_count = 0; X byte_count = count; X } X else X { X long_count = count >> 2; /* Assumes sizeof(long) is 4 */ X byte_count = count & 03; X } X 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( --long_count >= 0 ) X *--((long *) to) = *--((long *) from); X } X else X { X while( --long_count >= 0 ) X *((long *) to)++ = *((long *) from)++; X X while( --byte_count >= 0 ) X *to++ = *from++; X } X X return( temp_to ); X } / ---------------------------------------------------------- Terrence W. Holm uunet!uw-beaver!uvicctr!tholm tholm%uvunix.bitnet tholm%sirius.UVic.ca@relay.ubc.ca