From 4994155e731e0a3e1c63362caeabe155c1a9fffc Mon Sep 17 00:00:00 2001 From: Vreixo Formoso Date: Thu, 3 Jan 2008 23:52:27 +0100 Subject: [PATCH] Allow selection of charset encoding for RR names. TODO: do the same with link destination. --- src/fs_image.c | 30 ++++++++++++++++++++++++++++-- src/fs_image.h | 6 ++++-- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/src/fs_image.c b/src/fs_image.c index 73683e6..7ebcbe6 100644 --- a/src/fs_image.c +++ b/src/fs_image.c @@ -19,6 +19,8 @@ #include #include +#include +#include static int ifs_fs_open(IsoImageFilesystem *fs); @@ -66,6 +68,7 @@ typedef struct struct libiso_msgs *messenger; char *input_charset; /**< Input charset for RR names */ + char *local_charset; /**< For RR names, will be set to the locale one */ /** * Will be filled with the block lba of the extend for the root directory, @@ -871,7 +874,22 @@ int iso_file_source_new_ifs(IsoImageFilesystem *fs, IsoFileSource *parent, return ret; } - //TODO convert name to needed charset!! + /* convert name to needed charset */ + if (strcmp(fsdata->input_charset, fsdata->local_charset) && name) { + /* we need to convert name charset */ + char *newname = NULL; + ret = strconv(name, fsdata->input_charset, fsdata->local_charset, + &newname); + if (ret < 0) { + iso_msg_sorry(fsdata->messenger, LIBISO_CHARSET_ERROR, + "Charset conversion error. Can't convert %s from %s to %s", + name, fsdata->input_charset, fsdata->local_charset); + free(newname); + } else { + free(name); + name = newname; + } + } } else { /* RR extensions are not read / used */ @@ -1459,8 +1477,16 @@ int iso_image_filesystem_new(IsoDataSource *src, struct iso_read_opts *opts, data->gid = opts->gid; data->uid = opts->uid; data->mode = opts->mode & ~S_IFMT; - data->input_charset = strdup(opts->input_charset); data->messenger = opts->messenger; + + data->input_charset = strdup(opts->input_charset); + + setlocale(LC_CTYPE, ""); + data->local_charset = strdup(nl_langinfo(CODESET)); + if (data->local_charset == NULL) { + ret = ISO_MEM_ERROR; + goto fs_cleanup; + } ifs->open = ifs_fs_open; ifs->close = ifs_fs_close; diff --git a/src/fs_image.h b/src/fs_image.h index 9c7d8ae..6cb0dad 100644 --- a/src/fs_image.h +++ b/src/fs_image.h @@ -38,9 +38,11 @@ */ struct iso_read_opts { - uint32_t block; /** Block where the image begins, usually 0, can be - * different on a multisession disc. + /** + * Block where the image begins, usually 0, can be different on a + * multisession disc. */ + uint32_t block; unsigned int norock : 1; /*< Do not read Rock Ridge extensions */ unsigned int nojoliet : 1; /*< Do not read Joliet extensions */