From 71ea8f3b06f3ce627afc7433829da0051e49c5cc Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Mon, 10 Feb 2025 21:33:10 +0100 Subject: [PATCH] CLIMG-74691 Provide a hook to setup iconv path at runtime --- oficonv/include/dcmtk/oficonv/iconv.h | 6 ++++++ oficonv/libsrc/citrus_bcs.c | 16 ++++++++++++++++ oficonv/libsrc/oficonv_iconv.c | 1 + 3 files changed, 23 insertions(+) diff --git a/oficonv/include/dcmtk/oficonv/iconv.h b/oficonv/include/dcmtk/oficonv/iconv.h index 8170e7b43a..14a4842bf6 100644 --- a/oficonv/include/dcmtk/oficonv/iconv.h +++ b/oficonv/include/dcmtk/oficonv/iconv.h @@ -309,6 +309,12 @@ DCMTK_OFICONV_EXPORT char *OFiconv_canonicalize(const char *name); */ DCMTK_OFICONV_EXPORT int OFiconvctl(iconv_t cd, int request, void *argument); +/** This function define a runtime path where to look for the oficonv db files. + * This path is used only after the env variable DCMICONVPATH. + * @param path to the location of esdb folder + */ +DCMTK_OFICONV_EXPORT void OFiconv_setpath(const char *iconv_path); + /// space holder type for OFlocale_charset(). typedef struct { char spaceholder[20]; diff --git a/oficonv/libsrc/citrus_bcs.c b/oficonv/libsrc/citrus_bcs.c index d514dcf711..3010d0e827 100644 --- a/oficonv/libsrc/citrus_bcs.c +++ b/oficonv/libsrc/citrus_bcs.c @@ -25,12 +25,25 @@ */ #include "dcmtk/config/osconfig.h" +#include "dcmtk/oficonv/iconv.h" #include "citrus_bcs.h" #include #include #include +char *oficonv_path = NULL; + +void OFiconv_setpath(const char *runtime_path) { + if (oficonv_path) { + free(oficonv_path); + oficonv_path = NULL; + } + if (runtime_path) { + oficonv_path = strdup(runtime_path); + } +} + /* * case insensitive comparison between two C strings. */ @@ -184,6 +197,9 @@ void get_data_path(char *path_out, size_t path_size, const char *dirname, const // retrieve the DCMICONVPATH environment variable env = getenv(OFICONV_PATH_VARIABLE); + // if the environment variable is not set, use the runtime oficonv path instead: + if ( env == NULL && oficonv_path != NULL ) env = oficonv_path; + // if the environment variable is not set, use DEFAULT_SUPPORT_DATA_DIR instead if (env == NULL) env = DEFAULT_SUPPORT_DATA_DIR; diff --git a/oficonv/libsrc/oficonv_iconv.c b/oficonv/libsrc/oficonv_iconv.c index abed5a10f9..a20cfe9b6e 100644 --- a/oficonv/libsrc/oficonv_iconv.c +++ b/oficonv/libsrc/oficonv_iconv.c @@ -378,4 +378,5 @@ const char *OFlocale_charset(iconv_locale_allocation_t *buf) void OFiconv_cleanup() { _citrus_csmapper_free(); + OFiconv_setpath(NULL); }