(trunk libT) Use tr_strndup() instead of tr_strdup() in tr_urlParse() to avoid a couple of strlen() calls
This commit is contained in:
parent
ac3ec2db39
commit
1e0f92ba78
|
@ -1010,8 +1010,10 @@ tr_urlParse( const char * url_in,
|
|||
int n;
|
||||
char * tmp;
|
||||
char * pch;
|
||||
const char * protocol = NULL;
|
||||
size_t host_len;
|
||||
size_t protocol_len;
|
||||
const char * host = NULL;
|
||||
const char * protocol = NULL;
|
||||
const char * path = NULL;
|
||||
|
||||
tmp = tr_strndup( url_in, len );
|
||||
|
@ -1019,12 +1021,14 @@ tr_urlParse( const char * url_in,
|
|||
{
|
||||
*pch = '\0';
|
||||
protocol = tmp;
|
||||
protocol_len = pch - protocol;
|
||||
pch += 3;
|
||||
/*fprintf( stderr, "protocol is [%s]... what's left is [%s]\n", protocol, pch);*/
|
||||
if( ( n = strcspn( pch, ":/" ) ) )
|
||||
{
|
||||
const int havePort = pch[n] == ':';
|
||||
host = pch;
|
||||
host_len = n;
|
||||
pch += n;
|
||||
*pch++ = '\0';
|
||||
/*fprintf( stderr, "host is [%s]... what's left is [%s]\n", host, pch );*/
|
||||
|
@ -1053,10 +1057,10 @@ tr_urlParse( const char * url_in,
|
|||
|
||||
if( !err )
|
||||
{
|
||||
if( setme_protocol ) *setme_protocol = tr_strdup( protocol );
|
||||
if( setme_protocol ) *setme_protocol = tr_strndup( protocol, protocol_len );
|
||||
|
||||
if( setme_host ){ ( (char*)host )[-3] = ':'; *setme_host =
|
||||
tr_strdup( host ); }
|
||||
tr_strndup( host, host_len ); }
|
||||
if( setme_path ){ if( path[0] == '/' ) *setme_path = tr_strdup( path );
|
||||
else { ( (char*)path )[-1] = '/'; *setme_path = tr_strdup( path - 1 ); } }
|
||||
if( setme_port ) *setme_port = port;
|
||||
|
|
Loading…
Reference in New Issue