get_filename tried to work around this with hardcoded strings that end with a '/', but would fail to work properly for environment variables XDG_DATA_HOME or XDG_DATA_DIRS that don't do the same. --- mimedb.c | 14 +++++++++----- 1 files changed, 9 insertions(+), 5 deletions(-)
diff --git a/mimedb.c b/mimedb.c index b62d4eb..11c3250 100644 --- a/mimedb.c +++ b/mimedb.c @@ -240,7 +240,9 @@ static char * search_ini( const char *filename, const char *match ) */ static char *file_exists( const char *dir, const char *in ) { - char *filename = my_malloc( strlen( dir ) + strlen(in) + 1 ); + int dir_len = strlen( dir ); + int need_sep = dir[dir_len - 1] != '/'; + char *filename = my_malloc( dir_len + need_sep + strlen( in ) + 1 ); char *replaceme; struct stat buf; @@ -251,7 +253,9 @@ static char *file_exists( const char *dir, const char *in ) return 0; } strcpy( filename, dir ); - strcat( filename, in ); + if ( need_sep ) + filename[dir_len++] = '/'; + strcpy( filename + dir_len, in ); if( !stat( filename, &buf ) ) return filename; @@ -309,12 +313,12 @@ static char *get_filename( char *f ) { char *guessed_xdg_home; - guessed_xdg_home = my_malloc (strlen (home) + strlen ("/.local/share/") + 1); + guessed_xdg_home = my_malloc (strlen (home) + strlen ("/.local/share") + 1); if( !guessed_xdg_home ) return 0; strcpy (guessed_xdg_home, home); - strcat (guessed_xdg_home, "/.local/share/"); + strcat (guessed_xdg_home, "/.local/share"); result = file_exists( guessed_xdg_home, f ); free (guessed_xdg_home); @@ -325,7 +329,7 @@ static char *get_filename( char *f ) xdg_data_dirs = getenv ("XDG_DATA_DIRS"); if (xdg_data_dirs == NULL) - xdg_data_dirs = "/usr/local/share/:/usr/share/"; + xdg_data_dirs = "/usr/local/share:/usr/share"; ptr = xdg_data_dirs; -- 1.7.2.3 ------------------------------------------------------------------------------ Increase Visibility of Your 3D Game App & Earn a Chance To Win $500! Tap into the largest installed PC base & get more eyes on your game by optimizing for Intel(R) Graphics Technology. Get started today with the Intel(R) Software Partner Program. Five $500 cash prizes are up for grabs. http://p.sf.net/sfu/intelisp-dev2dev _______________________________________________ Fish-users mailing list Fish-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/fish-users