home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_disks / 300-399 / ff319.lzh / CNewsSrc / cnews.orig.lzh / libfake / memchr.c < prev    next >
C/C++ Source or Header  |  1989-06-27  |  577b  |  36 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. #define    NULL    0
  9.  
  10. #ifndef CHARBITS
  11. #    define    UNSCHAR(c)    ((unsigned char)(c))
  12. #else
  13. #    define    UNSCHAR(c)    ((c)&CHARBITS)
  14. #endif
  15.  
  16. char *
  17. memchr(s, ucharwanted, size)
  18.  char * s;
  19. int ucharwanted;
  20. int size;
  21. {
  22.     register  char *scan;
  23.     register int n;
  24.     register int uc;
  25.  
  26.     scan = s;
  27.     uc = UNSCHAR(ucharwanted);
  28.     for (n = size; n > 0; n--)
  29.         if (UNSCHAR(*scan) == uc)
  30.             return(scan);
  31.         else
  32.             scan++;
  33.  
  34.     return(NULL);
  35. }
  36.