Skip to content

Commit

Permalink
posix: drop support for non-UTF-8 operating systems
Browse files Browse the repository at this point in the history
This patch also removes support for legacy encodings:
 - in taglib, in the non-Windows code paths,
 - in the Internationalized Domain Names resolved (only glibc) and
 - in the GNOME VFS module.

Support for translation from/to UTF-8 was disabled by default 20 months
ago, and scheduled for removal, 14 months ago.
  • Loading branch information
Rémi Denis-Courmont committed Mar 19, 2012
1 parent 7f3120a commit bc032f3
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 141 deletions.
8 changes: 0 additions & 8 deletions bin/cachegen.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@
#include <stdlib.h>
#include <stdbool.h>

#ifdef HAVE_SETLOCALE
# include <locale.h>
#endif

#ifdef HAVE_GETOPT_H
# include <getopt.h>
#endif
Expand Down Expand Up @@ -63,10 +59,6 @@ int main (int argc, char *argv[])
{ NULL, no_argument, NULL, '\0'}
};

#ifdef HAVE_SETLOCALE
setlocale (LC_CTYPE, ""); /* needed by FromLocale() */
#endif

int c;
bool force = false;

Expand Down
7 changes: 1 addition & 6 deletions modules/access/gnomevfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@

#include <libgnomevfs/gnome-vfs.h>


#include <vlc_charset.h>
#include <vlc_url.h>

/*****************************************************************************
Expand Down Expand Up @@ -87,7 +85,6 @@ static int Open( vlc_object_t *p_this )
access_t *p_access = (access_t*)p_this;
access_sys_t *p_sys = NULL;
char *psz_name = NULL;
char *psz = NULL;
char *psz_uri = NULL;
char *psz_unescaped = NULL;
char *psz_expand_tilde = NULL;
Expand Down Expand Up @@ -121,9 +118,7 @@ static int Open( vlc_object_t *p_this )
{
psz_name = strdup( p_access->psz_location );
}
psz = ToLocale( psz_name );
psz_expand_tilde = gnome_vfs_expand_initial_tilde( psz );
LocaleFree( psz );
psz_expand_tilde = gnome_vfs_expand_initial_tilde( psz_name );

psz_unescaped = gnome_vfs_make_uri_from_shell_arg( psz_expand_tilde );

Expand Down
16 changes: 2 additions & 14 deletions modules/meta_engine/taglib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
#include <vlc_plugin.h>
#include <vlc_demux.h> /* demux_meta_t */
#include <vlc_strings.h> /* vlc_b64_decode_binary */
#include <vlc_charset.h> /* ToLocale, LocaleFree */
#include <vlc_input.h> /* for attachment_new */

#ifdef WIN32
Expand Down Expand Up @@ -458,14 +457,7 @@ static int ReadMeta( vlc_object_t* p_this)
f = FileRef( wpath );
free( wpath );
#else
const char* local_name = ToLocale( psz_path );
if( !local_name )
{
free( psz_path );
return VLC_EGENERIC;
}
f = FileRef( local_name );
LocaleFree( local_name );
f = FileRef( psz_path );
#endif
free( psz_path );

Expand Down Expand Up @@ -687,11 +679,7 @@ static int WriteMeta( vlc_object_t *p_this )
f = FileRef( wpath );
free( wpath );
#else
const char* local_name = ToLocale( p_export->psz_file );
if( !local_name )
return VLC_EGENERIC;
f = FileRef( local_name );
LocaleFree( local_name );
f = FileRef( p_export->psz_file );
#endif

if( f.isNull() || !f.tag() || f.file()->readOnly() )
Expand Down
3 changes: 0 additions & 3 deletions src/network/getaddrinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
#endif

#include <vlc_common.h>
#include <vlc_charset.h>

#include <stddef.h> /* size_t */
#include <string.h> /* strlen(), memcpy(), memset(), strchr() */
Expand Down Expand Up @@ -157,7 +156,6 @@ int vlc_getaddrinfo( vlc_object_t *p_this, const char *node,
}

int ret;
node = ToLocale (node);
#ifdef WIN32
/*
* Winsock tries to resolve numerical IPv4 addresses as AAAA
Expand Down Expand Up @@ -186,6 +184,5 @@ int vlc_getaddrinfo( vlc_object_t *p_this, const char *node,
#if defined(AI_IDN) || defined(WIN32)
out:
#endif
LocaleFree (node);
return ret;
}
3 changes: 1 addition & 2 deletions src/posix/darwin_dirs.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
#include <vlc_common.h>

#include "../libvlc.h"
#include <vlc_charset.h>
#include <vlc_configuration.h>
#include "config/configuration.h"

Expand Down Expand Up @@ -139,7 +138,7 @@ static char *config_GetHomeDir (void)
if (home == NULL)
home = "/tmp";

return FromLocaleDup (home);
return strdup (home);
}

static char *getAppDependentDir(vlc_userdir_t type)
Expand Down
16 changes: 6 additions & 10 deletions src/posix/dirs.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
#include <vlc_common.h>

#include "../libvlc.h"
#include <vlc_charset.h>
#include "config/configuration.h"

#include <unistd.h>
Expand Down Expand Up @@ -87,7 +86,7 @@ static char *config_GetHomeDir (void)
if (!home)
return NULL;

return FromLocaleDup (home);
return strdup (home);
}

static char *config_GetAppDir (const char *xdg_name, const char *xdg_default)
Expand All @@ -98,16 +97,15 @@ static char *config_GetAppDir (const char *xdg_name, const char *xdg_default)
/* XDG Base Directory Specification - Version 0.6 */
snprintf (var, sizeof (var), "XDG_%s_HOME", xdg_name);

char *psz_home = FromLocale (getenv (var));
if( psz_home )
const char *home = getenv (var);
if (home != NULL)
{
if( asprintf( &psz_dir, "%s/vlc", psz_home ) == -1 )
if (asprintf (&psz_dir, "%s/vlc", home) == -1)
psz_dir = NULL;
LocaleFree (psz_home);
return psz_dir;
}

psz_home = config_GetHomeDir ();
char *psz_home = config_GetHomeDir ();
if( psz_home == NULL
|| asprintf( &psz_dir, "%s/%s/vlc", psz_home, xdg_default ) == -1 )
psz_dir = NULL;
Expand Down Expand Up @@ -215,9 +213,7 @@ static char *config_GetTypeDir (const char *xdg_name)
path = strdup (home);
}

char *ret = FromLocaleDup (path);
free (path);
return ret;
return path;
}


Expand Down
99 changes: 9 additions & 90 deletions src/posix/filesystem.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
#include <sys/socket.h>

#include <vlc_common.h>
#include <vlc_charset.h>
#include <vlc_fs.h>
#include "libvlc.h" /* vlc_mkdir */

Expand All @@ -69,19 +68,9 @@ int vlc_open (const char *filename, int flags, ...)
flags |= O_CLOEXEC;
#endif

const char *local_name = ToLocale (filename);

if (local_name == NULL)
{
errno = ENOENT;
return -1;
}

int fd = open (local_name, flags, mode);
int fd = open (filename, flags, mode);
if (fd != -1)
fcntl (fd, F_SETFD, FD_CLOEXEC);

LocaleFree (local_name);
return fd;
}

Expand Down Expand Up @@ -109,24 +98,15 @@ int vlc_openat (int dir, const char *filename, int flags, ...)
flags |= O_CLOEXEC;
#endif

const char *local_name = ToLocale (filename);
if (local_name == NULL)
{
errno = ENOENT;
return -1;
}

#ifdef HAVE_OPENAT
int fd = openat (dir, local_name, flags, mode);
int fd = openat (dir, filename, flags, mode);
if (fd != -1)
fcntl (fd, F_SETFD, FD_CLOEXEC);
#else
int fd = -1;
errno = ENOSYS;
(void) mode;
#endif

LocaleFree (local_name);
return fd;
}

Expand All @@ -141,16 +121,7 @@ int vlc_openat (int dir, const char *filename, int flags, ...)
*/
int vlc_mkdir (const char *dirname, mode_t mode)
{
char *locname = ToLocale (dirname);
if (unlikely(locname == NULL))
{
errno = ENOENT;
return -1;
}

int res = mkdir (locname, mode);
LocaleFree (locname);
return res;
return mkdir (dirname, mode);
}

/**
Expand Down Expand Up @@ -221,30 +192,11 @@ char *vlc_readdir( DIR *dir )
if (val != 0)
errno = val;
else if (ent != NULL)
#ifndef __APPLE__
path = FromLocaleDup (ent->d_name);
#else
path = FromCharset ("UTF-8-MAC", ent->d_name, strlen (ent->d_name));
#endif
path = strdup (ent->d_name);
free (buf);
return path;
}

static int vlc_statEx (const char *filename, struct stat *buf, bool deref)
{
const char *local_name = ToLocale (filename);
if (unlikely(local_name == NULL))
{
errno = ENOENT;
return -1;
}

int res = deref ? stat (local_name, buf)
: lstat (local_name, buf);
LocaleFree (local_name);
return res;
}

/**
* Finds file/inode information, as stat().
* Consider using fstat() instead, if possible.
Expand All @@ -253,7 +205,7 @@ static int vlc_statEx (const char *filename, struct stat *buf, bool deref)
*/
int vlc_stat (const char *filename, struct stat *buf)
{
return vlc_statEx (filename, buf, true);
return stat (filename, buf);
}

/**
Expand All @@ -264,7 +216,7 @@ int vlc_stat (const char *filename, struct stat *buf)
*/
int vlc_lstat (const char *filename, struct stat *buf)
{
return vlc_statEx (filename, buf, false);
return lstat (filename, buf);
}

/**
Expand All @@ -276,16 +228,7 @@ int vlc_lstat (const char *filename, struct stat *buf)
*/
int vlc_unlink (const char *filename)
{
const char *local_name = ToLocale (filename);
if (unlikely(local_name == NULL))
{
errno = ENOENT;
return -1;
}

int ret = unlink (local_name);
LocaleFree (local_name);
return ret;
return unlink (filename);
}

/**
Expand All @@ -298,23 +241,7 @@ int vlc_unlink (const char *filename)
*/
int vlc_rename (const char *oldpath, const char *newpath)
{
const char *lo = ToLocale (oldpath);
if (lo == NULL)
goto error;

const char *ln = ToLocale (newpath);
if (ln == NULL)
{
LocaleFree (lo);
error:
errno = ENOENT;
return -1;
}

int ret = rename (lo, ln);
LocaleFree (lo);
LocaleFree (ln);
return ret;
return rename (oldpath, newpath);
}

/**
Expand All @@ -333,7 +260,7 @@ char *vlc_getcwd (void)
/* Make sure $PWD is correct */
if (stat (pwd, &s1) == 0 && stat (".", &s2) == 0
&& s1.st_dev == s2.st_dev && s1.st_ino == s2.st_ino)
return ToLocaleDup (pwd);
return strdup (pwd);
}

/* Otherwise iterate getcwd() until the buffer is big enough */
Expand All @@ -347,15 +274,7 @@ char *vlc_getcwd (void)
break;

if (getcwd (buf, size) != NULL)
#ifdef ASSUME_UTF8
return buf;
#else
{
char *ret = ToLocaleDup (buf);
free (buf);
return ret; /* success */
}
#endif
free (buf);

if (errno != ERANGE)
Expand Down
Loading

0 comments on commit bc032f3

Please sign in to comment.