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.
This commit is contained in:
Thomas Schmitt 2009-03-19 12:56:25 +01:00
parent 183ed6cc5a
commit da2619c42a
6 changed files with 52 additions and 2 deletions

View File

@ -954,11 +954,13 @@ int ecma119_image_new(IsoImage *src, IsoWriteOpts *opts, Ecma119Image **img)
target->eltorito = (src->bootcat == NULL ? 0 : 1); target->eltorito = (src->bootcat == NULL ? 0 : 1);
target->catalog = src->bootcat; target->catalog = src->bootcat;
#ifdef Libisofs_setlocale_in_iniT
/* default to locale charset */ /* default to locale charset */
/* ??? ts Nov 25 2008 : /* ??? ts Nov 25 2008 :
Shouldn't this go to library initialization or even to app ? Shouldn't this go to library initialization or even to app ?
*/ */
setlocale(LC_CTYPE, ""); setlocale(LC_CTYPE, "");
#endif
target->input_charset = strdup(iso_get_local_charset(0)); target->input_charset = strdup(iso_get_local_charset(0));

View File

@ -2153,10 +2153,12 @@ int iso_image_filesystem_new(IsoDataSource *src, struct iso_read_opts *opts,
data->aaip_load = !opts->noaaip; data->aaip_load = !opts->noaaip;
data->aaip_version = -1; data->aaip_version = -1;
#ifdef Libisofs_setlocale_in_iniT
/* ??? ts Nov 25 2008 : /* ??? ts Nov 25 2008 :
Shouldn't this go to library initialization or even to app ? Shouldn't this go to library initialization or even to app ?
*/ */
setlocale(LC_CTYPE, ""); setlocale(LC_CTYPE, "");
#endif
data->local_charset = strdup(iso_get_local_charset(0)); data->local_charset = strdup(iso_get_local_charset(0));
if (data->local_charset == NULL) { if (data->local_charset == NULL) {

View File

@ -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 * @return 1 on success, < 0 on error
* *
* @since 0.6.2 * @since 0.6.2
*/ */
int iso_init(); 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. * Finalize libisofs.
* *
@ -4830,5 +4843,8 @@ struct burn_source {
#define Libisofs_with_iso_iconV yes #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_*/ #endif /*LIBISO_LIBISOFS_H_*/

View File

@ -15,6 +15,9 @@
#include "libisofs.h" #include "libisofs.h"
#include "messages.h" #include "messages.h"
#include "util.h"
/* /*
* error codes are 32 bit numbers, that follow the following conventions: * 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; 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_msgr == NULL) {
if (libiso_msgs_new(&libiso_msgr, 0) <= 0) if (libiso_msgs_new(&libiso_msgr, 0) <= 0)
return ISO_FATAL_ERROR; return ISO_FATAL_ERROR;
@ -66,6 +76,12 @@ int iso_init()
return 1; return 1;
} }
int iso_init()
{
return iso_init_with_flag(0);
}
void iso_finish() void iso_finish()
{ {
libiso_msgs_destroy(&libiso_msgr, 0); libiso_msgs_destroy(&libiso_msgr, 0);

View File

@ -1619,10 +1619,12 @@ char *ucs2str(const char *buf, size_t len)
/* convert to local charset */ /* convert to local charset */
#ifdef Libisofs_setlocale_in_iniT
/* ??? ts Nov 25 2008 : /* ??? ts Nov 25 2008 :
Shouldn't this go to library initialization or even to app ? Shouldn't this go to library initialization or even to app ?
*/ */
setlocale(LC_CTYPE, ""); setlocale(LC_CTYPE, "");
#endif
#ifdef Libisofs_with_iso_iconV #ifdef Libisofs_with_iso_iconV
conv_ret = iso_iconv_open(&conv, iso_get_local_charset(0), "UCS-2BE", 0); 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))); || (cminor == minor && cmicro >= micro)));
} }
int iso_init_locale(int flag)
{
setlocale(LC_CTYPE, "");
return 1;
}

View File

@ -25,6 +25,11 @@
int int_pow(int base, int power); 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. * Convert the charset encoding of a given string.
* *