[vlc-commits] commit: FileToUrl: constify ( Rémi Denis-Courmont )
git at videolan.org
git at videolan.org
Tue Mar 9 22:49:53 CET 2010
vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Tue Mar 9 23:41:47 2010 +0200| [924ed95fdb21cad0be138ea5600fcc7b0b848725] | committer: Rémi Denis-Courmont
FileToUrl: constify
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=924ed95fdb21cad0be138ea5600fcc7b0b848725
---
modules/control/http/util.c | 46 +++++++++++++++----------------------------
1 files changed, 16 insertions(+), 30 deletions(-)
diff --git a/modules/control/http/util.c b/modules/control/http/util.c
index adeea06..1b26dee 100644
--- a/modules/control/http/util.c
+++ b/modules/control/http/util.c
@@ -40,49 +40,35 @@
****************************************************************************/
/* 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;
- if( !url || !p )
- {
+
+ char *url = malloc( strlen( name ) + 2 );
+ if( unlikely(url == NULL) )
return NULL;
- }
-#ifdef WIN32
- while( *name == '\\' || *name == '/' )
+#if (DIR_SEP_CHAR == '/')
+ name += strspn( name, "/" );
#else
- while( *name == '/' )
+ name += strspn( name, "/"DIR_SEP );
#endif
- {
- name++;
- }
+ *url = '/';
+ strcpy( url + 1, name );
- *p++ = '/';
- strcpy( p, name );
-
-#ifdef WIN32
+#if (DIR_SEP_CHAR != '/')
/* convert '\\' into '/' */
- name = p;
- while( *name )
- {
- if( *name == '\\' )
+ for( char *ptr = url; *ptr; ptr++ )
+ if( *ptr == DIR_SEP_CHAR )
*name = '/';
- name++;
- }
#endif
/* 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;
}
More information about the vlc-commits
mailing list