From 1c1496ab7d36cd2f9b6701f4e504feeca0a84bbe Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Tue, 8 Mar 2022 18:58:23 +0200 Subject: [PATCH 45/45] Construct absolute locale path to pass to bindtextdomain() If LOCALEDIR is a relative path, construct absolute path out of it in get_locale_dir(). This makes localization of the gui clients to work with the current msys2 environment. See osdn #44047 Signed-off-by: Marko Lindqvist --- configure.ac | 2 +- gen_headers/meson_fc_config.h.in | 3 +++ meson.build | 1 + utility/fcintl.c | 35 +++++++++++++++++++++++++++++++- 4 files changed, 39 insertions(+), 2 deletions(-) diff --git a/configure.ac b/configure.ac index 530decde42..4e5c32185a 100644 --- a/configure.ac +++ b/configure.ac @@ -1499,7 +1499,7 @@ AC_CHECK_FUNCS([bind connect fileno flock ftime gethostbyname gethostname]) AC_CHECK_FUNCS([getpwuid inet_aton select snooze strcasestr]) AC_CHECK_FUNCS([strerror strstr uname nanosleep usleep]) AC_CHECK_FUNCS([getline _strcoll stricoll _stricoll strcasecoll]) -AC_CHECK_FUNCS([backtrace setenv putenv]) +AC_CHECK_FUNCS([backtrace setenv putenv getcwd]) dnl Possible random sources AC_CHECK_HEADERS([sys/random.h]) diff --git a/gen_headers/meson_fc_config.h.in b/gen_headers/meson_fc_config.h.in index c7af6b2a50..2bea1938c9 100644 --- a/gen_headers/meson_fc_config.h.in +++ b/gen_headers/meson_fc_config.h.in @@ -303,6 +303,9 @@ /* putenv() available */ #mesondefine HAVE_PUTENV +/* getcwd() available */ +#mesondefine HAVE_GETCWD + /* select() available */ #mesondefine HAVE_SELECT diff --git a/meson.build b/meson.build index 1711f1b897..22bad96594 100644 --- a/meson.build +++ b/meson.build @@ -193,6 +193,7 @@ priv_functions = [ 'inet_pton', 'opendir', 'putenv', + 'getcwd', 'select', 'setenv', 'snooze', diff --git a/utility/fcintl.c b/utility/fcintl.c index b93d7d9e94..c4f4de5022 100644 --- a/utility/fcintl.c +++ b/utility/fcintl.c @@ -101,8 +101,41 @@ bool is_capitalization_enabled(void) /*******************************************************************//** Return directory containing locales. + In a rare cases this can be a relative path, but it tries + to return absolute path when ever possible. ***********************************************************************/ const char *get_locale_dir(void) { - return LOCALEDIR; + static bool ldbuf_init = FALSE; + static char buf[4096]; + + if (!ldbuf_init) { + /* FIXME: On Windows, also something starting with the drive, + * e.g., "C:\", can be absolute path. Paths like that + * are never used with our currently supported setups. + * + * Can't check just against DIR_SEPARATOR_CHAR as the mingw + * layer may have converted path to use '/' even on Windows. + */ + if (LOCALEDIR[0] != '/' || LOCALEDIR[0] != '\\') { + char *cwdbuf; + +#ifdef HAVE_GETCWD + cwdbuf = getcwd(NULL, 0); +#else + /* Can't help it. Must construct relative path. */ + cwdbuf = fc_strdup("."); +#endif + + fc_snprintf(buf, sizeof(buf), "%s" DIR_SEPARATOR LOCALEDIR, cwdbuf); + + free(cwdbuf); + } else { + strncpy(buf, LOCALEDIR, sizeof(buf)); + } + + ldbuf_init = TRUE; + } + + return buf; } -- 2.34.1