strchr.c 202 B

1234567891011121314151617181920
  1. #include <u.h>
  2. #include <libc.h>
  3. char*
  4. strchr(char *s, int c)
  5. {
  6. char c0 = c;
  7. char c1;
  8. if(c == 0) {
  9. while(*s++)
  10. ;
  11. return s-1;
  12. }
  13. while(c1 = *s++)
  14. if(c1 == c0)
  15. return s-1;
  16. return 0;
  17. }