home *** CD-ROM | disk | FTP | other *** search
/ Atari FTP / ATARI_FTP_0693.zip / ATARI_FTP_0693 / Mint / mntlib25.zoo / memchr.c < prev    next >
C/C++ Source or Header  |  1992-09-17  |  717b  |  39 lines

  1. /* from Henry Spencer's stringlib */
  2.  
  3. #include <stddef.h>
  4. #include <string.h>
  5.  
  6. /*
  7.  * memchr - search for a byte
  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. void *
  20. memchr(s, ucharwanted, size)
  21. const void * s;
  22. int ucharwanted;
  23. size_t size;
  24. {
  25.     register const char *scan;
  26.     register size_t n;
  27.     register int uc;
  28.  
  29.     scan = (const char *) s;
  30.     uc = UNSCHAR(ucharwanted);
  31.     for (n = size; n > 0; n--)
  32.         if (UNSCHAR(*scan) == uc)
  33.             return((void *)scan);
  34.         else
  35.             scan++;
  36.  
  37.     return(NULL);
  38. }
  39.