{
char *key, *val;
key = (char *) malloc(strlen(gedcom_n) + strlen(charwidth) + 3);
val = (char *) malloc(strlen(iconv_n) + 1);
{
char *key, *val;
key = (char *) malloc(strlen(gedcom_n) + strlen(charwidth) + 3);
val = (char *) malloc(strlen(iconv_n) + 1);
- /* sprintf is safe here (malloc'ed before) */
- sprintf(key, "%s(%s)", gedcom_n, charwidth);
- strcpy(val, iconv_n);
-
- if (hash_lookup(encodings, key)) {
- gedcom_warning(_("Duplicate entry found for encoding '%s', ignoring"),
- gedcom_n);
- free(key);
- free(val);
- }
- else {
- hash_alloc_insert(encodings, key, val);
+ if (key && val) {
+ /* sprintf is safe here (malloc'ed before) */
+ sprintf(key, "%s(%s)", gedcom_n, charwidth);
+ strcpy(val, iconv_n);
+
+ if (hash_lookup(encodings, key)) {
+ gedcom_warning(_("Duplicate entry found for encoding '%s', ignoring"),
+ gedcom_n);
+ free(key);
+ free(val);
+ }
+ else {
+ hash_alloc_insert(encodings, key, val);
+ }
- node = hash_lookup(encodings, key);
- free(key);
- if (node) {
- return hnode_get(node);
+ if (key) {
+ /* sprintf is safe here (malloc'ed before) */
+ sprintf(key, "%s(%s)", gedcom_n, charwidth_string[enc]);
+
+ node = hash_lookup(encodings, key);
+ free(key);
+ if (node) {
+ return hnode_get(node);
+ }
+ else {
+ gedcom_error(_("No encoding defined for '%s'"), gedcom_n);
+ return NULL;
+ }
/* Let function be called before main() */
void update_gconv_search_path() __attribute__ ((constructor));
/* Let function be called before main() */
void update_gconv_search_path() __attribute__ ((constructor));
char *gconv_path;
/* Add gedcom data directory to gconv search path */
gconv_path = getenv(GCONV_SEARCH_PATH);
if (gconv_path == NULL || strstr(gconv_path, PKGDATADIR) == NULL) {
char *gconv_path;
/* Add gedcom data directory to gconv search path */
gconv_path = getenv(GCONV_SEARCH_PATH);
if (gconv_path == NULL || strstr(gconv_path, PKGDATADIR) == NULL) {
- sprintf(new_gconv_path, "%s=%s", GCONV_SEARCH_PATH, PKGDATADIR);
+ if (new_gconv_path)
+ sprintf(new_gconv_path, "%s=%s", GCONV_SEARCH_PATH, PKGDATADIR);
- sprintf(new_gconv_path, "%s=%s:%s",
- GCONV_SEARCH_PATH, gconv_path, PKGDATADIR);
+ if (new_gconv_path)
+ sprintf(new_gconv_path, "%s=%s:%s",
+ GCONV_SEARCH_PATH, gconv_path, PKGDATADIR);
+ }
+ if (new_gconv_path)
+ /* Ignore failures of putenv (can't do anything about it anyway) */
+ putenv(new_gconv_path);
+ else {
+ fprintf(stderr, "Could not allocate memory at %s, %d\n",
+ __FILE__, __LINE__);
+ abort();
encodings = hash_create(HASHCOUNT_T_MAX, NULL, NULL);
hash_set_allocator(encodings, node_alloc, node_free, NULL);
encodings = hash_create(HASHCOUNT_T_MAX, NULL, NULL);
hash_set_allocator(encodings, node_alloc, node_free, NULL);
- gedcom_warning(_("Could not open encoding configuration file '%s'"),
- ENCODING_CONF_FILE);
+ gedcom_warning(_("Could not open encoding configuration file '%s': %s"),
+ ENCODING_CONF_FILE, strerror(errno));
- char *encoding = get_encoding(fromcode, the_enc);
- if (cd_to_internal != (iconv_t) -1)
- iconv_close(cd_to_internal);
+ iconv_t new_cd_to_internal;
+ const char *encoding = get_encoding(fromcode, the_enc);
- cd_to_internal = iconv_open(INTERNAL_ENCODING, encoding);
- if (cd_to_internal == (iconv_t) -1) {
+ new_cd_to_internal = iconv_open(INTERNAL_ENCODING, encoding);
+ if (new_cd_to_internal == (iconv_t) -1) {
gedcom_error(_("Error opening conversion context for encoding %s: %s"),
encoding, strerror(errno));
}
}
gedcom_error(_("Error opening conversion context for encoding %s: %s"),
encoding, strerror(errno));
}
}
- return (cd_to_internal != (iconv_t) -1);
+ if (new_cd_to_internal != (iconv_t) -1) {
+ if (cd_to_internal != (iconv_t) -1)
+ iconv_close(cd_to_internal);
+ cd_to_internal = new_cd_to_internal;
+ }
+ return (new_cd_to_internal != (iconv_t) -1);
- iconv_close(cd_to_internal);
- cd_to_internal = (iconv_t) -1;
+ if (cd_to_internal != (iconv_t) -1) {
+ if (iconv_close(cd_to_internal) != 0) {
+ gedcom_warning(_("Error closing conversion context: %s"),
+ strerror(errno));
+ }
+ cd_to_internal = (iconv_t) -1;
+ }
char* output_buffer, size_t out_len)
{
size_t res;
size_t outsize = out_len;
char *wrptr = output_buffer;
char* output_buffer, size_t out_len)
{
size_t res;
size_t outsize = out_len;
char *wrptr = output_buffer;
char *retval = output_buffer;
/* set up input buffer (concatenate to what was left previous time) */
/* can't use strcpy, because possible null bytes from unicode */
char *retval = output_buffer;
/* set up input buffer (concatenate to what was left previous time) */
/* can't use strcpy, because possible null bytes from unicode */
}
/* then shift what is left over to the head of the input buffer */
memmove(conv_buf, rdptr, conv_buf_size);
}
/* then shift what is left over to the head of the input buffer */
memmove(conv_buf, rdptr, conv_buf_size);