Changeset 8449


Ignore:
Timestamp:
May 20, 2009, 4:25:45 AM (12 years ago)
Author:
charles
Message:

(trunk libT) make tr_memmem() more readable

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/utils.c

    r8430 r8449  
    689689
    690690const char*
    691 tr_memmem( const char * s1, size_t l1, /* haystack */
    692            const char * s2, size_t l2 ) /* needle */
     691tr_memmem( const char * haystack, size_t haystacklen,
     692           const char * needle, size_t needlelen )
    693693{
    694694#ifdef HAVE_MEMMEM
    695     return memmem( s1, l1, s2, l2 );
     695    return memmem( haystack, haystacklen, needle, needlelen );
    696696#else
    697     if( !l2 ) return s1;
    698     while( l1 >= l2 )
    699     {
    700         l1--;
    701         if( !memcmp( s1, s2, l2 ) )
    702             return s1;
    703         s1++;
    704     }
     697    const char *h = haystack;
     698    const char *n = needle;
     699    size_t i;
     700
     701    for( i=0; i<haystacklen-needlelen; ++i )
     702        if( !memcmp( h+i, n, needlelen ) )
     703            return h+i;
     704
    705705    return NULL;
    706706#endif
Note: See TracChangeset for help on using the changeset viewer.