*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
/**
# include <limits.h>
#endif
+#ifdef HAVE_UNISTD_H
+# include <unistd.h>
+#endif
+
#include <ctype.h>
/**
char *psz_fname_original = strdup( psz_name );
char *psz_fname = psz_fname_original;
+ if( psz_fname == NULL ) return NULL;
+
if( !strncmp( psz_fname, "file://", 7 ) )
{
psz_fname += 7;
f_fname = malloc( strlen(tmp) );
if( f_fname )
strcpy( f_fname, tmp+1 ); // we skip the seperator, so it will still fit in the allocated space
- dirlen = strlen(psz_fname) - strlen(tmp);
+ dirlen = strlen(psz_fname) - strlen(tmp) + 1; // add the seperator
f_dir = malloc( dirlen + 1 );
if( f_dir )
{
- strncpy( f_dir, psz_fname, dirlen + 1 );
+ strncpy( f_dir, psz_fname, dirlen );
f_dir[dirlen] = 0;
}
}
else
{
+ /* Get the current working directory */
+#ifdef HAVE_UNISTD_H
+ f_dir = getcwd( NULL, 0 );
+#endif
+ if( f_dir == NULL )
+ {
+ if( psz_fname_original ) free( psz_fname_original );
+ return NULL;
+ }
f_fname = strdup( psz_fname );
}
pp_dir_content = NULL;
i_dir_content = 0;
+ if( j < 0 && f_dir == NULL )
+ continue;
+
/* parse psz_src dir */
if( ( i_dir_content = scandir( j < 0 ? f_dir : *subdirs, &pp_dir_content, Filter,
NULL ) ) != -1 )
if( i_prio >= fuzzy.i_int )
{
FILE *f;
- char *tmpresult;
+ char *psz_UTF8_path;
+ char *psz_locale_path;
- asprintf( &tmpresult, "%s%s", j < 0 ? f_dir : *subdirs, p_fixed_name );
+ asprintf( &psz_UTF8_path, "%s%s", j < 0 ? f_dir : *subdirs, p_fixed_name );
+ psz_locale_path = ToLocale( psz_UTF8_path );
msg_Dbg( p_this, "autodetected subtitle: %s with priority %d", p_fixed_name, i_prio );
- if( ( f = fopen( tmpresult, "rt" ) ) )
+ if( ( f = fopen( psz_locale_path, "rt" ) ) )
{
fclose( f );
+ LocaleFree( psz_locale_path );
result[i_sub_count].priority = i_prio;
- result[i_sub_count].psz_fname = tmpresult;
+ result[i_sub_count].psz_fname = psz_UTF8_path;
result[i_sub_count].psz_ext = strdup(tmp_fname_ext);
i_sub_count++;
- } else free( tmpresult );
+ }
+ else
+ {
+ if( psz_UTF8_path ) free( psz_UTF8_path );
+ LocaleFree( psz_locale_path );
+ }
}
if( i_sub_count >= MAX_SUBTITLE_FILES ) break;
- free( p_fixed_name );
+ if( p_fixed_name ) free( p_fixed_name );
}
+ for( a = 0; a < i_dir_content; a++ )
+ if( pp_dir_content[a] ) free( pp_dir_content[a] );
+ if( pp_dir_content ) free( pp_dir_content );
}
- if( j >= 0 ) free( *subdirs++ );
+ if( j >= 0 ) if( *subdirs ) free( *subdirs++ );
}
if( tmp_subdirs ) free( tmp_subdirs );