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