Win32: use IsProcessorFeaturePresent() to detect available instructions
[vlc/solaris.git] / include / vlc_charset.h
blobab6d5299a67ed9f06256accd10bc94ff6b1d4c77
1 /*****************************************************************************
2 * charset.h: Unicode UTF-8 wrappers function
3 *****************************************************************************
4 * Copyright (C) 2003-2005 the VideoLAN team
5 * Copyright © 2005-2006 Rémi Denis-Courmont
6 * $Id$
8 * Author: Rémi Denis-Courmont <rem # videolan,org>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
25 #ifndef VLC_CHARSET_H
26 #define VLC_CHARSET_H 1
28 /**
29 * \file
30 * This files handles locale conversions in vlc
33 #include <stdarg.h>
34 #include <sys/types.h>
35 #include <dirent.h>
37 VLC_EXPORT( void, LocaleFree, ( const char * ) );
38 VLC_EXPORT( char *, FromLocale, ( const char * ) LIBVLC_USED );
39 VLC_EXPORT( char *, FromLocaleDup, ( const char * ) LIBVLC_USED );
40 VLC_EXPORT( char *, ToLocale, ( const char * ) LIBVLC_USED );
41 VLC_EXPORT( char *, ToLocaleDup, ( const char * ) LIBVLC_USED );
43 /* TODO: move all of this to "vlc_fs.h" or something like that */
44 VLC_EXPORT( int, utf8_open, ( const char *filename, int flags, ... ) LIBVLC_USED );
45 VLC_EXPORT( FILE *, utf8_fopen, ( const char *filename, const char *mode ) LIBVLC_USED );
46 VLC_EXPORT( DIR *, utf8_opendir, ( const char *dirname ) LIBVLC_USED );
47 VLC_EXPORT( char *, utf8_readdir, ( DIR *dir ) LIBVLC_USED );
48 VLC_EXPORT( int, utf8_loaddir, ( DIR *dir, char ***namelist, int (*select)( const char * ), int (*compar)( const char **, const char ** ) ) );
49 VLC_EXPORT( int, utf8_scandir, ( const char *dirname, char ***namelist, int (*select)( const char * ), int (*compar)( const char **, const char ** ) ) );
50 VLC_EXPORT( int, utf8_mkdir, ( const char *filename, mode_t mode ) );
51 VLC_EXPORT( int, utf8_unlink, ( const char *filename ) );
52 int utf8_rename( const char *, const char * );
54 #if defined( WIN32 ) && !defined( UNDER_CE )
55 # define stat _stati64
56 #endif
58 VLC_EXPORT( int, utf8_stat, ( const char *filename, struct stat *buf ) );
59 VLC_EXPORT( int, utf8_lstat, ( const char *filename, struct stat *buf ) );
61 VLC_EXPORT( int, utf8_vfprintf, ( FILE *stream, const char *fmt, va_list ap ) );
62 VLC_EXPORT( int, utf8_fprintf, ( FILE *, const char *, ... ) LIBVLC_FORMAT( 2, 3 ) );
64 VLC_EXPORT( int, utf8_mkstemp, ( char * ) );
66 VLC_EXPORT( char *, EnsureUTF8, ( char * ) );
67 VLC_EXPORT( const char *, IsUTF8, ( const char * ) LIBVLC_USED );
69 #ifdef WIN32
70 LIBVLC_USED
71 static inline char *FromWide (const wchar_t *wide)
73 size_t len = WideCharToMultiByte (CP_UTF8, 0, wide, -1, NULL, 0, NULL, NULL);
74 if (len == 0)
75 return NULL;
77 char *out = (char *)malloc (len);
79 if (out)
80 WideCharToMultiByte (CP_UTF8, 0, wide, -1, out, len, NULL, NULL);
81 return out;
83 #endif
85 /**
86 * Converts a nul-terminated string from ISO-8859-1 to UTF-8.
88 static inline char *FromLatin1 (const char *latin)
90 char *str = (char *)malloc (2 * strlen (latin) + 1), *utf8 = str;
91 unsigned char c;
93 if (str == NULL)
94 return NULL;
96 while ((c = *(latin++)) != '\0')
98 if (c >= 0x80)
100 *(utf8++) = 0xC0 | (c >> 6);
101 *(utf8++) = 0x80 | (c & 0x3F);
103 else
104 *(utf8++) = c;
106 *(utf8++) = '\0';
108 utf8 = (char *)realloc (str, utf8 - str);
109 return utf8 ? utf8 : str;
112 VLC_EXPORT( const char *, GetFallbackEncoding, ( void ) LIBVLC_USED );
114 VLC_EXPORT( double, us_strtod, ( const char *, char ** ) LIBVLC_USED );
115 VLC_EXPORT( float, us_strtof, ( const char *, char ** ) LIBVLC_USED );
116 VLC_EXPORT( double, us_atof, ( const char * ) LIBVLC_USED );
117 VLC_EXPORT( int, us_asprintf, ( char **, const char *, ... ) LIBVLC_USED );
119 #endif