Commit 924ed95f authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

FileToUrl: constify

parent 96ea7e8d
...@@ -40,49 +40,35 @@ ...@@ -40,49 +40,35 @@
****************************************************************************/ ****************************************************************************/
/* ToUrl: create a good name for an url from filename */ /* ToUrl: create a good name for an url from filename */
static char *FileToUrl( char *name, bool *pb_index ) static char *FileToUrl( const char *name, bool *pb_index )
{ {
char *url, *p;
url = p = malloc( strlen( name ) + 1 );
*pb_index = false; *pb_index = false;
if( !url || !p )
{ char *url = malloc( strlen( name ) + 2 );
if( unlikely(url == NULL) )
return NULL; return NULL;
}
#ifdef WIN32 #if (DIR_SEP_CHAR == '/')
while( *name == '\\' || *name == '/' ) name += strspn( name, "/" );
#else #else
while( *name == '/' ) name += strspn( name, "/"DIR_SEP );
#endif #endif
{ *url = '/';
name++; strcpy( url + 1, name );
}
*p++ = '/'; #if (DIR_SEP_CHAR != '/')
strcpy( p, name );
#ifdef WIN32
/* convert '\\' into '/' */ /* convert '\\' into '/' */
name = p; for( char *ptr = url; *ptr; ptr++ )
while( *name ) if( *ptr == DIR_SEP_CHAR )
{
if( *name == '\\' )
*name = '/'; *name = '/';
name++;
}
#endif #endif
/* index.* -> / */ /* index.* -> / */
if( ( p = strrchr( url, '/' ) ) != NULL ) char *p = strrchr( url, '/' );
if( p != NULL && !strncmp( p, "/index.", 7 ) )
{ {
if( !strncmp( p, "/index.", 7 ) ) p[1] = '\0';
{ *pb_index = true;
p[1] = '\0';
*pb_index = true;
}
} }
return url; return url;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment