strchr.c revision 1.4
1/* $NetBSD: strchr.c,v 1.4 2016/01/08 21:35:42 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 29static char * 30strchr(char const *s, int c); 31 32static char * 33strrchr(char const *s, int c); 34 35static char * 36strchr(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 47static char * 48strrchr(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