~ubuntu-branches/ubuntu/trusty/ruby1.9/trusty

« back to all changes in this revision

Viewing changes to missing/strstr.c

  • Committer: Bazaar Package Importer
  • Author(s): Lucas Nussbaum
  • Date: 2006-05-08 22:23:12 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20060508222312-w2wqeaz030ifi59j
Tags: 1.9.0+20060423-3ubuntu1
* Resynchronized with Debian.
* Only change from Debian is the addition of
  debian/patches/903_sparc_fix_define.patch to fix illegal instructions
  at runtime on sparc. (change from 1.9.0+20050921-1ubuntu1)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* public domain rewrite of strstr(3) */
2
2
 
3
3
char *
4
 
strstr(haystack, needle)
5
 
    char *haystack, *needle;
 
4
strstr(const char *haystack, const char *needle)
6
5
{
7
 
    char *hend;
8
 
    char *a, *b;
 
6
    const char *hend;
 
7
    const char *a, *b;
9
8
 
10
 
    if (*needle == 0) return haystack;
 
9
    if (*needle == 0) return (char *)haystack;
11
10
    hend = haystack + strlen(haystack) - strlen(needle) + 1;
12
11
    while (haystack < hend) {
13
12
        if (*haystack == *needle) {
14
13
            a = haystack;
15
14
            b = needle;
16
15
            for (;;) {
17
 
                if (*b == 0) return haystack;
 
16
                if (*b == 0) return (char *)haystack;
18
17
                if (*a++ != *b++) {
19
18
                    break;
20
19
                }