home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
GEMini Atari
/
GEMini_Atari_CD-ROM_Walnut_Creek_December_1993.iso
/
zip
/
mint
/
mntlib16.lzh
/
MNTLIB16
/
BCMP.C
< prev
next >
Wrap
C/C++ Source or Header
|
1993-08-03
|
1KB
|
55 lines
#include <stddef.h>
#include <string.h>
#include <assert.h>
#undef ODD
#define ODD(x) (((short)(x)) & 1) /* word ops are faster */
/*
* compare n bytes efficientlty
*
* odd/even handled correctly
*
* ++jrb bammi@dsrgsun.ces.cwru.edu
*/
int bcmp(src, dst, n)
const register void * src;
const register void * dst;
register size_t n;
{
assert ((src != NULL) && (dst != NULL));
if((src != dst) && (n > 0))
{
register size_t l, w;
switch(ODD(src) + ODD(dst))
{
case 2: /* ODD ODD */
if(*(char *)dst++ != *(char *)src++)
return 1;
n--;
/* fall thru */
case 0: /* EVEN EVEN */
l = (n >> 2); /* # of longs */
n -= (l << 2);
w = (n >> 1); /* # of words */
n -= (w << 1); /* n == # of residual bytes */
while(l--)
if( *((long *)dst)++ != *((long *)src)++ )
return 1;
while(w--)
if( *((short *)dst)++ != *((short *)src)++ )
return 1;
/* fall thru */
case 1: /* ODD/EVEN or EVEN/ODD */
while(n--)
if( *(char *)dst++ != *(char *)src++ )
return 1;
}
}
return 0;
}