aboutsummaryrefslogtreecommitdiff
path: root/libgfortran/runtime
diff options
context:
space:
mode:
authorjb <jb@138bc75d-0d04-0410-961f-82ee72b054a4>2014-11-10 00:17:16 +0000
committerjb <jb@138bc75d-0d04-0410-961f-82ee72b054a4>2014-11-10 00:17:16 +0000
commitb8a8c7bc682b7ababe4a98dbd64b618c1e955f65 (patch)
tree632705719333408c765e7eddf68dc9b1418b8854 /libgfortran/runtime
parent69f332e9133bca0a302c1e1898c3c612258bd0ca (diff)
PR 47007 and 61847 Locale failures in libgfortran.
2014-11-10 Janne Blomqvist <jb@gcc.gnu.org> PR libfortran/47007 PR libfortran/61847 * config.h.in: Regenerated. * configure: Regenerated. * configure.ac (AC_CHECK_HEADERS_ONCE): Check for xlocale.h. (AC_CHECK_FUNCS_ONCE): Check for newlocale, freelocale, uselocale, strerror_l. * io/io.h (locale.h): Include. (xlocale.h): Include if present. (c_locale): New variable. (old_locale): New variable. (old_locale_ctr): New variable. (old_locale_lock): New variable. (st_parameter_dt): Add old_locale member. * io/transfer.c (data_transfer_init): Set locale to "C" if doing formatted transfer. (finalize_transfer): Reset locale to previous. * io/unit.c (c_locale): New variable. (old_locale): New variable. (old_locale_ctr): New variable. (old_locale_lock): New variable. (init_units): Init c_locale, init old_locale_lock. (close_units): Free c_locale. * runtime/error.c (locale.h): Include. (xlocale.h): Include if present. (gf_strerror): Use strerror_l if available. Reset locale to LC_GLOBAL_LOCALE for strerror_r branch. 2014-11-10 Janne Blomqvist <jb@gcc.gnu.org> PR libfortran/47007 PR libfortran/61847 * gfortran.texi: Add note about locale issues to thread-safety section. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@217273 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libgfortran/runtime')
-rw-r--r--libgfortran/runtime/error.c23
1 files changed, 21 insertions, 2 deletions
diff --git a/libgfortran/runtime/error.c b/libgfortran/runtime/error.c
index 4bde33ba723..7a3a1b744ed 100644
--- a/libgfortran/runtime/error.c
+++ b/libgfortran/runtime/error.c
@@ -46,6 +46,13 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
#endif
+#include <locale.h>
+
+#ifdef HAVE_XLOCALE_H
+#include <xlocale.h>
+#endif
+
+
#ifdef __MINGW32__
#define HAVE_GETPID 1
#include <process.h>
@@ -204,14 +211,26 @@ gfc_xtoa (GFC_UINTEGER_LARGEST n, char *buffer, size_t len)
}
-/* Hopefully thread-safe wrapper for a strerror_r() style function. */
+/* Hopefully thread-safe wrapper for a strerror() style function. */
char *
gf_strerror (int errnum,
char * buf __attribute__((unused)),
size_t buflen __attribute__((unused)))
{
-#ifdef HAVE_STRERROR_R
+#ifdef HAVE_STRERROR_L
+ locale_t myloc = newlocale (LC_CTYPE_MASK | LC_MESSAGES_MASK, "",
+ (locale_t) 0);
+ char *p = strerror_l (errnum, myloc);
+ freelocale (myloc);
+ return p;
+#elif defined(HAVE_STRERROR_R)
+#ifdef HAVE_USELOCALE
+ /* Some targets (Darwin at least) have the POSIX 2008 extended
+ locale functions, but not strerror_l. So reset the per-thread
+ locale here. */
+ uselocale (LC_GLOBAL_LOCALE);
+#endif
/* POSIX returns an "int", GNU a "char*". */
return
__builtin_choose_expr (__builtin_classify_type (strerror_r (0, buf, 0))