]> git.sesse.net Git - vlc/commitdiff
- UF8 wrappers for stat, lstat
authorRémi Denis-Courmont <rem@videolan.org>
Sun, 12 Feb 2006 19:48:50 +0000 (19:48 +0000)
committerRémi Denis-Courmont <rem@videolan.org>
Sun, 12 Feb 2006 19:48:50 +0000 (19:48 +0000)
- FromLocaleDup() returns a string to be freed with free() instead of LocaleFree()

configure.ac
include/charset.h
include/vlc_symbols.h
src/misc/unicode.c

index c5efd8dd4a65320046e4ea3ed8fa51dfbd3d3617..5fe50690b9bda5c378a30ecf4535ebb424d20d9a 100644 (file)
@@ -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)
index 8577e435901fbab625b34bd2fd92243da0a74347..357aae65776ca9b0cff321e3b31cec410238275e 100644 (file)
@@ -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 * ) );
index 8efad521e9b08e9b359084ccae178527b291f82b..126f8c3086927b11cd0f48a6c59fd6859c073db3 100644 (file)
@@ -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; \
index b3333f2c1fd279828a960b7ca10a19aed5f8d3be..44369b1efa8aacf849d5e0afd3a5d823adba3052 100644 (file)
@@ -1,7 +1,7 @@
 /*****************************************************************************
  * 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>
 #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
  *****************************************************************************