1/*	$NetBSD: strchr.c,v 1.1.1.1 2009/12/13 16:57:25 kardel 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
29char*
30strchr( char const *s, int c)
31{
32    do {
33        if ((unsigned)*s == (unsigned)c)
34            return s;
35
36    } while (*(++s) != NUL);
37
38    return NULL;
39}
40
41char*
42strrchr( char const *s, int c)
43{
44    char const *e = s + strlen(s);
45
46    for (;;) {
47        if (--e < s)
48            break;
49
50        if ((unsigned)*e == (unsigned)c)
51            return e;
52    }
53    return NULL;
54}
55
56/*
57 * Local Variables:
58 * mode: C
59 * c-file-style: "stroustrup"
60 * indent-tabs-mode: nil
61 * End:
62 * end of compat/strsignal.c */
63