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

- UF8 wrappers for stat, lstat

- FromLocaleDup() returns a string to be freed with free() instead of LocaleFree()
parent 9ef44504
......@@ -382,7 +382,7 @@ CPPFLAGS_save="${CPPFLAGS_save} -DSYS_`echo ${SYS} | sed -e 's/-.*//' | tr 'abcd
dnl Check for system libs needed
need_libc=false
AC_CHECK_FUNCS(gettimeofday select strerror strtod strtol strtof strtoll strtoull strsep isatty vasprintf asprintf swab sigrelse getpwuid memalign posix_memalign if_nametoindex atoll getenv putenv setenv gmtime_r ctime_r localtime_r lrintf daemon scandir fork bsearch assert)
AC_CHECK_FUNCS(gettimeofday select strerror strtod strtol strtof strtoll strtoull strsep isatty vasprintf asprintf swab sigrelse getpwuid memalign posix_memalign if_nametoindex atoll getenv putenv setenv gmtime_r ctime_r localtime_r lrintf daemon scandir fork bsearch lstat assert)
dnl Check for usual libc functions
AC_CHECK_FUNCS(strdup strndup atof)
......
......@@ -35,6 +35,8 @@ VLC_EXPORT( char *, ToLocale, ( const char * ) );
VLC_EXPORT( FILE *, utf8_fopen, ( const char *filename, const char *mode ) );
VLC_EXPORT( void *, utf8_opendir, ( const char *dirname ) );
VLC_EXPORT( const char *, utf8_readdir, ( void *dir ) );
VLC_EXPORT( int, utf8_stat, ( const char *filename, void *buf ) );
VLC_EXPORT( int, utf8_lstat, ( const char *filename, void *buf ) );
VLC_EXPORT( char *, EnsureUTF8, ( char * ) );
VLC_EXPORT( char *, FromUTF32, ( const wchar_t * ) );
VLC_EXPORT( char *, __vlc_fix_readdir_charset, ( vlc_object_t *, const char * ) );
......
......@@ -37,6 +37,7 @@ playlist_item_t * playlist_ItemGetByPos (playlist_t *, int);
int playlist_Clear (playlist_t *);
vout_thread_t * __vout_Create (vlc_object_t *, video_format_t *);
void aout_FormatPrint (aout_instance_t * p_aout, const char * psz_text, const audio_sample_format_t * p_format);
int utf8_stat (const char *filename, void *buf);
void vlm_ScheduleDelete (vlm_t *, vlm_schedule_t *, const char *);
void osd_ConfigUnload (vlc_object_t *, osd_menu_t **);
void input_DecoderDelete (decoder_t *);
......@@ -44,6 +45,7 @@ void __msg_Info (vlc_object_t *, const char *, ... ) ATTRIBUTE_FORMAT( 2, 3);
int playlist_ViewDump (playlist_t *, playlist_view_t *);
int __net_Select (vlc_object_t *p_this, int *pi_fd, v_socket_t **, int i_fd, uint8_t *p_data, int i_data, mtime_t i_wait);
aout_instance_t * __aout_New (vlc_object_t *);
int utf8_lstat (const char *filename, void *buf);
const char * VLC_Compiler (void);
void vout_DatePicture (vout_thread_t *, picture_t *, mtime_t);
int __var_Type (vlc_object_t *, const char *);
......@@ -360,8 +362,8 @@ char * mstrtime (char *psz_buffer, mtime_t date);
void aout_FormatPrepare (audio_sample_format_t * p_format);
void spu_DisplaySubpicture (spu_t *, subpicture_t *);
int intf_RunThread (intf_thread_t *);
int httpd_StreamSend (httpd_stream_t *, uint8_t *p_data, int i_data);
decoder_t * input_DecoderNew (input_thread_t *, es_format_t *, vlc_bool_t b_force_decoder);
int httpd_StreamSend (httpd_stream_t *, uint8_t *p_data, int i_data);
xml_t * __xml_Create (vlc_object_t *);
void* vlc_HashRetrieve (hashtable_entry_t*, int, int, const char *);
msg_subscription_t* __msg_Subscribe (vlc_object_t *, int);
......@@ -931,6 +933,8 @@ struct module_symbols_t
void * (*utf8_opendir_inner) (const char *dirname);
FILE * (*utf8_fopen_inner) (const char *filename, const char *mode);
const char * (*utf8_readdir_inner) (void *dir);
int (*utf8_stat_inner) (const char *filename, void *buf);
int (*utf8_lstat_inner) (const char *filename, void *buf);
};
# if defined (__PLUGIN__)
# define aout_FiltersCreatePipeline (p_symbols)->aout_FiltersCreatePipeline_inner
......@@ -1381,6 +1385,8 @@ struct module_symbols_t
# define utf8_opendir (p_symbols)->utf8_opendir_inner
# define utf8_fopen (p_symbols)->utf8_fopen_inner
# define utf8_readdir (p_symbols)->utf8_readdir_inner
# define utf8_stat (p_symbols)->utf8_stat_inner
# define utf8_lstat (p_symbols)->utf8_lstat_inner
# elif defined (HAVE_DYNAMIC_PLUGINS) && !defined (__BUILTIN__)
/******************************************************************
* STORE_SYMBOLS: store VLC APIs into p_symbols for plugin access.
......@@ -1834,6 +1840,8 @@ struct module_symbols_t
((p_symbols)->utf8_opendir_inner) = utf8_opendir; \
((p_symbols)->utf8_fopen_inner) = utf8_fopen; \
((p_symbols)->utf8_readdir_inner) = utf8_readdir; \
((p_symbols)->utf8_stat_inner) = utf8_stat; \
((p_symbols)->utf8_lstat_inner) = utf8_lstat; \
(p_symbols)->net_ConvertIPv4_deprecated = NULL; \
(p_symbols)->__stats_CounterGet_deprecated = NULL; \
(p_symbols)->__stats_TimerDumpAll_deprecated = NULL; \
......
/*****************************************************************************
* unicode.c: UTF8 <-> locale functions
*****************************************************************************
* Copyright (C) 2005 the VideoLAN team
* Copyright (C) 2005-2006 the VideoLAN team
* $Id$
*
* Authors: Rémi Denis-Courmont <rem # videolan.org>
......@@ -34,8 +34,15 @@
#endif
#include <stdio.h>
#include <errno.h>
#include <sys/types.h>
#include <dirent.h>
#ifdef HAVE_SYS_STAT_H
# include <sys/stat.h>
#endif
#ifndef HAVE_LSTAT
# define lstat( a, b ) stat(a, b)
#endif
#ifdef __APPLE__
/* Define this if the OS always use UTF-8 internally */
......@@ -190,6 +197,20 @@ char *FromLocale( const char *locale )
#endif
}
char *FromLocaleDup( const char *locale )
{
#if defined (ASSUME_UTF8)
return strdup( locale );
#else
# ifdef USE_ICONV
if (from_locale.hd == (vlc_iconv_t)(-1))
return strdup( locale );
# endif
return FromLocale( locale );
#endif
}
/*****************************************************************************
* ToLocale: converts an UTF-8 string to locale
*****************************************************************************/
......@@ -269,14 +290,19 @@ FILE *utf8_fopen( const char *filename, const char *mode )
LocaleFree( local_name );
return stream;
}
else
errno = ENOENT;
return NULL;
#else
wchar_t wpath[MAX_PATH];
wchar_t wmode[4];
if( !MultiByteToWideChar( CP_UTF8, 0, filename, -1, wpath, MAX_PATH - 1)
|| !MultiByteToWideChar( CP_ACP, 0, mode, -1, wmode, 3 ) )
if( !MultiByteToWideChar( CP_UTF8, 0, filename, -1, wpath, MAX_PATH - 1)
|| !MultiByteToWideChar( CP_ACP, 0, mode, -1, wmode, 3 ) )
{
errno = ENOENT;
return NULL;
}
return _wfopen( wpath, wmode );
#endif
......@@ -292,6 +318,8 @@ void *utf8_opendir( const char *dirname )
LocaleFree( local_name );
return dir;
}
else
errno = ENOENT;
return NULL;
}
......@@ -307,6 +335,35 @@ const char *utf8_readdir( void *dir )
}
static int utf8_statEx( const char *filename, void *buf,
vlc_bool_t deref )
{
#ifdef HAVE_SYS_STAT_H
const char *local_name = ToLocale( filename );
if( local_name != NULL )
{
int res = deref ? stat( local_name, (struct stat *)buf )
: lstat( local_name, (struct stat *)buf );
LocaleFree( local_name );
return res;
}
errno = ENOENT;
#endif
return -1;
}
int utf8_stat( const char *filename, void *buf)
{
return utf8_statEx( filename, buf, VLC_TRUE );
}
int utf8_lstat( const char *filename, void *buf)
{
return utf8_statEx( filename, buf, VLC_FALSE );
}
/*****************************************************************************
* EnsureUTF8: replaces invalid/overlong UTF-8 sequences with question marks
*****************************************************************************
......
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