1 /* $NetBSD: strchr.c,v 1.5 2020/05/25 20:47:35 christos Exp $ */ 2 3 /* 4 SYNOPSIS 5 #include <string.h> 6 7 char *strchr(char const *s, int c); 8 9 char *strrchr(char const *s, int c); 10 11 DESCRIPTION 12 The strchr() function returns a pointer to the first occurrence of the 13 character c in the string s. 14 15 The strrchr() function returns a pointer to the last occurrence of the 16 character c in the string s. 17 18 Here "character" means "byte" - these functions do not work with wide 19 or multi-byte characters. 20 21 RETURN VALUE 22 The strchr() and strrchr() functions return a pointer to the matched 23 character or NULL if the character is not found. 24 25 CONFORMING TO 26 SVID 3, POSIX, BSD 4.3, ISO 9899 27 */ 28 29 static char * 30 strchr(char const *s, int c); 31 32 static char * 33 strrchr(char const *s, int c); 34 35 static char * 36 strchr(char const *s, int c) 37 { 38 do { 39 if ((unsigned char)*s == (unsigned char)c) 40 return s; 41 42 } while (*(++s) != NUL); 43 44 return NULL; 45 } 46 47 static char * 48 strrchr(char const *s, int c) 49 { 50 char const *e = s + strlen(s); 51 52 for (;;) { 53 if (--e < s) 54 break; 55 56 if ((unsigned char)*e == (unsigned char)c) 57 return e; 58 } 59 return NULL; 60 } 61 62 /* 63 * Local Variables: 64 * mode: C 65 * c-file-style: "stroustrup" 66 * indent-tabs-mode: nil 67 * End: 68 * end of compat/strsignal.c */ 69