home *** CD-ROM | disk | FTP | other *** search
/ Scene Storm / Scene Storm - Volume 1.iso / coding / c / pdc / libsrc / stringlib / memchr.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-04-07  |  618 b   |  38 lines

  1. /*
  2.  * memchr - search for a byte
  3.  *
  4.  * CHARBITS should be defined only if the compiler lacks "unsigned char".
  5.  * It should be a mask, e.g. 0377 for an 8-bit machine.
  6.  */
  7.  
  8. #include "config.h"
  9.  
  10. #define    NULL    0
  11.  
  12. #ifndef CHARBITS
  13. #    define    UNSCHAR(c)    ((unsigned char)(c))
  14. #else
  15. #    define    UNSCHAR(c)    ((c)&CHARBITS)
  16. #endif
  17.  
  18. VOIDSTAR
  19. memchr(s, ucharwanted, size)
  20. CONST VOIDSTAR s;
  21. char ucharwanted;
  22. SIZET size;
  23. {
  24.     register CONST char *scan;
  25.     register SIZET n;
  26.     register char uc;
  27.  
  28.     scan = s;
  29.     uc = UNSCHAR(ucharwanted);
  30.     for (n = size; n > 0; n--)
  31.         if (UNSCHAR(*scan) == uc)
  32.             return(scan);
  33.         else
  34.             scan++;
  35.  
  36.     return(NULL);
  37. }
  38.