[vlc-devel] commit: Use strrchr() ( Rafaël Carré )

git version control git at videolan.org
Mon May 5 21:35:02 CEST 2008


vlc | branch: master | Rafaël Carré <funman at videolan.org> | Mon May  5 21:36:40 2008 +0200| [8d583016474dff4a5069940aff3b6d51592fdc51]

Use strrchr()

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=8d583016474dff4a5069940aff3b6d51592fdc51
---

 src/libvlc-common.c |   22 +++++++---------------
 1 files changed, 7 insertions(+), 15 deletions(-)

diff --git a/src/libvlc-common.c b/src/libvlc-common.c
index 31f6f69..149b4d7 100644
--- a/src/libvlc-common.c
+++ b/src/libvlc-common.c
@@ -248,23 +248,15 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc,
     system_Init( p_libvlc, &i_argc, ppsz_argv );
 
     /* Get the executable name (similar to the basename command) */
-    if( i_argc > 0 )
+    if( i_argc > 0 && ppsz_argv[0][0] )
     {
-        const char *psz_exe = ppsz_argv[0] + strlen( ppsz_argv[0] );
-        for( ; psz_exe > ppsz_argv[0] ; psz_exe-- )
-        {
-            if( *psz_exe == '/' )
-            {
-                psz_exe++;
-                break;
-            }
-        }
+        free( p_libvlc->psz_object_name );
 
-        if( *psz_exe )
-        {
-            free( p_libvlc->psz_object_name );
-            p_libvlc->psz_object_name = strdup( psz_exe );
-        }
+        const char *psz_exe = strrchr( ppsz_argv[0], '/' );
+        if( psz_exe && *(psz_exe + 1) )
+            p_libvlc->psz_object_name = strdup( psz_exe + 1 );
+        else
+            p_libvlc->psz_object_name = strdup( ppsz_argv[0] );
     }
 
     /*




More information about the vlc-devel mailing list