home *** CD-ROM | disk | FTP | other *** search
/ Atari FTP / ATARI_FTP_0693.zip / ATARI_FTP_0693 / Mint / mntlib32.zoo / memcmp.c < prev    next >
C/C++ Source or Header  |  1993-05-23  |  734b  |  40 lines

  1. /* from Henry Spencer's stringlib */
  2.  
  3. #include <stddef.h>
  4. #include <string.h>
  5.  
  6. /*
  7.  * memcmp - compare bytes
  8.  *
  9.  * CHARBITS should be defined only if the compiler lacks "unsigned char".
  10.  * It should be a mask, e.g. 0377 for an 8-bit machine.
  11.  */
  12.  
  13. #ifndef CHARBITS
  14. #    define    UNSCHAR(c)    ((unsigned char)(c))
  15. #else
  16. #    define    UNSCHAR(c)    ((c)&CHARBITS)
  17. #endif
  18.  
  19. int                /* <0, == 0, >0 */
  20. memcmp(s1, s2, size)
  21. const void * s1;
  22. const void * s2;
  23. size_t size;
  24. {
  25.     register const char *scan1;
  26.     register const char *scan2;
  27.     register size_t n;
  28.  
  29.     scan1 = (const char *) s1;
  30.     scan2 = (const char *) s2;
  31.     for (n = size; n > 0; n--)
  32.         if (*scan1 == *scan2) {
  33.             scan1++;
  34.             scan2++;
  35.         } else
  36.             return(UNSCHAR (*scan1) - UNSCHAR (*scan2));
  37.  
  38.     return(0);
  39. }
  40.