strchr.c (358B)
1 /* 2 * strchr.c - locate character in string 3 * Copyright (C) 2026. All rights reserved. 4 */ 5 6 #include "libc.h" 7 8 char *strchr(const char *s, int c) { 9 unsigned char chr = (unsigned char)c; 10 11 while (*s != '\0') { 12 if ((unsigned char)*s == chr) { 13 return (char *)s; 14 } 15 s++; 16 } 17 18 if (chr == '\0') { 19 return (char *)s; 20 } 21 22 return NULL; 23 }