From f010a0f5aacabfe6a9ce2714eb9a7b40534b7970 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Thu, 10 Mar 2022 20:03:22 +0200 Subject: [PATCH 19/22] 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 +- utility/fcintl.c | 39 ++++++++++++++++++++++++++++++++++++++- 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/configure.ac b/configure.ac index f8f1dc00f1..bd3fdb7343 100644 --- a/configure.ac +++ b/configure.ac @@ -1428,7 +1428,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/utility/fcintl.c b/utility/fcintl.c index cb903cfda0..e3fe8a3565 100644 --- a/utility/fcintl.c +++ b/utility/fcintl.c @@ -17,6 +17,10 @@ #include +#ifdef HAVE_UNISTD_H +#include +#endif + /* utility */ #include "mem.h" @@ -101,8 +105,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.35.1