source: trunk/essentials/sys-apps/gawk/missing_d/strchr.c

Last change on this file was 3076, checked in by bird, 18 years ago

gawk 3.1.5

File size: 749 bytes
Line 
1/*
2 * strchr --- search a string for a character
3 *
4 * We supply this routine for those systems that aren't standard yet.
5 */
6
7#if 0
8#include <stdio.h>
9#endif
10
11char *
12strchr(str, c)
13register const char *str, c;
14{
15 if (c == '\0') {
16 /* thanks to Mike Brennan ... */
17 do {
18 if (*str == c)
19 return (char *) str;
20 } while (*str++);
21 } else {
22 for (; *str; str++)
23 if (*str == c)
24 return (char *) str;
25 }
26
27 return NULL;
28}
29
30/*
31 * strrchr --- find the last occurrence of a character in a string
32 *
33 * We supply this routine for those systems that aren't standard yet.
34 */
35
36char *
37strrchr(str, c)
38register const char *str, c;
39{
40 register const char *save = NULL;
41
42 for (; *str; str++)
43 if (*str == c)
44 save = str;
45
46 return (char *) save;
47}
Note: See TracBrowser for help on using the repository browser.