mirror of
https://github.com/transmission/transmission
synced 2024-12-26 01:27:28 +00:00
(trunk libT) make tr_memmem() more readable
This commit is contained in:
parent
fb77a810d7
commit
af213891f9
1 changed files with 11 additions and 11 deletions
|
@ -688,20 +688,20 @@ tr_strndup( const void * in, int len )
|
||||||
}
|
}
|
||||||
|
|
||||||
const char*
|
const char*
|
||||||
tr_memmem( const char * s1, size_t l1, /* haystack */
|
tr_memmem( const char * haystack, size_t haystacklen,
|
||||||
const char * s2, size_t l2 ) /* needle */
|
const char * needle, size_t needlelen )
|
||||||
{
|
{
|
||||||
#ifdef HAVE_MEMMEM
|
#ifdef HAVE_MEMMEM
|
||||||
return memmem( s1, l1, s2, l2 );
|
return memmem( haystack, haystacklen, needle, needlelen );
|
||||||
#else
|
#else
|
||||||
if( !l2 ) return s1;
|
const char *h = haystack;
|
||||||
while( l1 >= l2 )
|
const char *n = needle;
|
||||||
{
|
size_t i;
|
||||||
l1--;
|
|
||||||
if( !memcmp( s1, s2, l2 ) )
|
for( i=0; i<haystacklen-needlelen; ++i )
|
||||||
return s1;
|
if( !memcmp( h+i, n, needlelen ) )
|
||||||
s1++;
|
return h+i;
|
||||||
}
|
|
||||||
return NULL;
|
return NULL;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue