From da2619c42aebabd4be64f9845cfb2e71af713e89 Mon Sep 17 00:00:00 2001 From: Thomas Schmitt Date: Thu, 19 Mar 2009 12:56:25 +0100 Subject: [PATCH] New API function iso_init_with_flag(). Moved setup of locale from various places to util.c:iso_init_locale(). It is now called by the iso_init*() functions only. --- libisofs/ecma119.c | 2 ++ libisofs/fs_image.c | 2 ++ libisofs/libisofs.h | 18 +++++++++++++++++- libisofs/messages.c | 18 +++++++++++++++++- libisofs/util.c | 9 +++++++++ libisofs/util.h | 5 +++++ 6 files changed, 52 insertions(+), 2 deletions(-) diff --git a/libisofs/ecma119.c b/libisofs/ecma119.c index 86c8209..aeeb787 100644 --- a/libisofs/ecma119.c +++ b/libisofs/ecma119.c @@ -954,11 +954,13 @@ int ecma119_image_new(IsoImage *src, IsoWriteOpts *opts, Ecma119Image **img) target->eltorito = (src->bootcat == NULL ? 0 : 1); target->catalog = src->bootcat; +#ifdef Libisofs_setlocale_in_iniT /* default to locale charset */ /* ??? ts Nov 25 2008 : Shouldn't this go to library initialization or even to app ? */ setlocale(LC_CTYPE, ""); +#endif target->input_charset = strdup(iso_get_local_charset(0)); diff --git a/libisofs/fs_image.c b/libisofs/fs_image.c index b8b3dd5..e3e9b03 100644 --- a/libisofs/fs_image.c +++ b/libisofs/fs_image.c @@ -2153,10 +2153,12 @@ int iso_image_filesystem_new(IsoDataSource *src, struct iso_read_opts *opts, data->aaip_load = !opts->noaaip; data->aaip_version = -1; +#ifdef Libisofs_setlocale_in_iniT /* ??? ts Nov 25 2008 : Shouldn't this go to library initialization or even to app ? */ setlocale(LC_CTYPE, ""); +#endif data->local_charset = strdup(iso_get_local_charset(0)); if (data->local_charset == NULL) { diff --git a/libisofs/libisofs.h b/libisofs/libisofs.h index 8dcac04..9958898 100644 --- a/libisofs/libisofs.h +++ b/libisofs/libisofs.h @@ -873,13 +873,26 @@ struct iso_stream }; /** - * Initialize libisofs. You must call this before any usage of the library. + * Initialize libisofs. Before any usage of the library you must either call + * this function or iso_init_with_flag(). * @return 1 on success, < 0 on error * * @since 0.6.2 */ int iso_init(); +/** + * Initialize libisofs. Before any usage of the library you must either call + * this function or iso_init() which is equivalent to iso_init_with_flag(0). + * @param flag + * Bitfield for control purposes + * bit0= do not set up locale by LC_* environment variables + * @return 1 on success, < 0 on error + * + * @since 0.6.18 + */ +int iso_init_with_flag(int flag); + /** * Finalize libisofs. * @@ -4830,5 +4843,8 @@ struct burn_source { #define Libisofs_with_iso_iconV yes */ +/* Cleanup : make call setlocale() at init time resp. never +*/ +#define Libisofs_setlocale_in_iniT yes #endif /*LIBISO_LIBISOFS_H_*/ diff --git a/libisofs/messages.c b/libisofs/messages.c index efa76df..ef4c5bc 100644 --- a/libisofs/messages.c +++ b/libisofs/messages.c @@ -15,6 +15,9 @@ #include "libisofs.h" #include "messages.h" +#include "util.h" + + /* * error codes are 32 bit numbers, that follow the following conventions: * @@ -55,8 +58,15 @@ int abort_threshold = LIBISO_MSGS_SEV_FAILURE; struct libiso_msgs *libiso_msgr = NULL; -int iso_init() + +/* + @param flag bit0= do not set up locale by LC_* environment variables +*/ +int iso_init_with_flag(int flag) { + if (! (flag & 1)) { + iso_init_locale(0); + } if (libiso_msgr == NULL) { if (libiso_msgs_new(&libiso_msgr, 0) <= 0) return ISO_FATAL_ERROR; @@ -66,6 +76,12 @@ int iso_init() return 1; } + +int iso_init() +{ + return iso_init_with_flag(0); +} + void iso_finish() { libiso_msgs_destroy(&libiso_msgr, 0); diff --git a/libisofs/util.c b/libisofs/util.c index aec8152..a6487da 100644 --- a/libisofs/util.c +++ b/libisofs/util.c @@ -1619,10 +1619,12 @@ char *ucs2str(const char *buf, size_t len) /* convert to local charset */ +#ifdef Libisofs_setlocale_in_iniT /* ??? ts Nov 25 2008 : Shouldn't this go to library initialization or even to app ? */ setlocale(LC_CTYPE, ""); +#endif #ifdef Libisofs_with_iso_iconV conv_ret = iso_iconv_open(&conv, iso_get_local_charset(0), "UCS-2BE", 0); @@ -1688,3 +1690,10 @@ int iso_lib_is_compatible(int major, int minor, int micro) || (cminor == minor && cmicro >= micro))); } +int iso_init_locale(int flag) +{ + setlocale(LC_CTYPE, ""); + return 1; +} + + diff --git a/libisofs/util.h b/libisofs/util.h index 5a9616c..28545d6 100644 --- a/libisofs/util.h +++ b/libisofs/util.h @@ -25,6 +25,11 @@ int int_pow(int base, int power); +/** + * Set up locale by LC_* environment variables. + */ +int iso_init_locale(int flag); + /** * Convert the charset encoding of a given string. *