Subversion Repositories Kolibri OS

Rev

Rev 8793 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 8793 Rev 9765
Line 1... Line 1...
1
/* strstr( const char *, const char * )
1
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
2
 
-
 
3
   This file is part of the Public Domain C Library (PDCLib).
2
#include "unconst.h"
4
   Permission is granted to use, modify, and / or redistribute at will.
-
 
5
*/
-
 
6
 
-
 
7
#include 
3
#include 
Line 8... Line 4...
8
 
4
 
9
char * strstr( const char * s1, const char * s2 )
-
 
10
{
-
 
11
    const char * p1 = s1;
-
 
12
    const char * p2;
-
 
13
 
-
 
14
    while ( *s1 )
5
char* strstr(const char* s, const char* find)
15
    {
6
{
-
 
7
    char c, sc;
Line 16... Line 8...
16
        p2 = s2;
8
    size_t len;
-
 
9
 
17
 
10
    if ((c = *find++) != 0) {
18
        while ( *p2 && ( *p1 == *p2 ) )
11
        len = strlen(find);
-
 
12
        do {
-
 
13
            do {
-
 
14
                if ((sc = *s++) == 0)
-
 
15
                    return 0;
19
        {
16
            } while (sc != c);
20
            ++p1;
17
        } while (strncmp(s, find, len) != 0);
21
            ++p2;
-
 
22
        }
-
 
23
 
-
 
24
        if ( ! *p2 )
18
        s--;
25
        {
-
 
26
            return ( char * ) s1;
-
 
27
        }
-
 
28
 
-
 
29
        ++s1;
-
 
30
        p1 = s1;
-
 
31
    }
-
 
32
 
19
    }
33
    return NULL;
20
    return unconst(s, char*);