From: Peter Verthez Date: Sun, 17 Mar 2002 13:04:19 +0000 (+0000) Subject: Add interface function gedcom_init(), to avoid problem with GCONV_PATH X-Git-Url: https://git.dlugolecki.net.pl/?a=commitdiff_plain;h=9cf569cd68164b6611101fefce7604edbad0b3ce;p=gedcom-parse.git Add interface function gedcom_init(), to avoid problem with GCONV_PATH modification (see note in encoding.c). --- diff --git a/gedcom/encoding.c b/gedcom/encoding.c index 9e4e919..d97f63c 100644 --- a/gedcom/encoding.c +++ b/gedcom/encoding.c @@ -102,6 +102,25 @@ void cleanup_encodings() /* Let function be called before main() */ void update_gconv_search_path() __attribute__ ((constructor)); +/* Note: + + The environment variable GCONV_PATH has to be adjusted before the very + first call of iconv_open. For the most general case, it means that we + have to make our own constructor here (in case some of the other library + constructors would use iconv_open). + + However, it looks like a change of an environment variable in a constructor + doesn't always survive until the main() function. This is the case if + the environment variable is a new one, for which there was no room yet + in the initial environment. The initial environment is located on the + stack, but when variables are added, it is moved to the heap (to be able + to grow). Now, the main function takes again the one from the stack, not + from the heap, so changes are lost. + + For this, the function below will also be called in gedcom_init(), which + needs to be called as early as possible in the program. + */ + void update_gconv_search_path() { char *gconv_path; diff --git a/gedcom/encoding.h b/gedcom/encoding.h index 6623e61..9eb40ba 100644 --- a/gedcom/encoding.h +++ b/gedcom/encoding.h @@ -37,5 +37,6 @@ char* to_internal(char* str, size_t len, char* output_buffer, size_t out_len); void init_encodings(); void set_encoding_width(ENCODING enc); +void update_gconv_search_path(); #endif /* __ENCODING_H */ diff --git a/gedcom/multilex.c b/gedcom/multilex.c index 42b9f50..727c179 100644 --- a/gedcom/multilex.c +++ b/gedcom/multilex.c @@ -105,6 +105,11 @@ int determine_encoding(FILE* f) } } +void gedcom_init() +{ + update_gconv_search_path(); +} + int gedcom_parse_file(char* file_name) { ENCODING enc;