@@ -24,7 +24,8 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
#include "libgfortran.h"
#include <signal.h>
-
+#include <locale.h>
+#include <string.h>
/* Useful compile-time options will be stored in here. */
compile_options_t compile_options;
@@ -161,6 +162,28 @@ set_options (int num, int options[])
compile_options.fpe_summary = options[6];
#ifndef LIBGFOR_MINIMAL
+
+ /* Set the locale. This is not selectable by a compile option, but
+ this should be setup only when using a Fortran main program, not
+ when loading libgfortran. */
+ setlocale (LC_ALL, "");
+ char *ctype_loc = setlocale (LC_CTYPE, NULL);
+ if (ctype_loc && strcmp (ctype_loc, "C") == 0)
+ {
+ /* Try to set the LC_CTYPE to a locale supporting UTF-8 even if
+ the environment specifies the default C locale. This is
+ similar to e.g. python (see PEP 538). */
+ setlocale (LC_CTYPE, "C.UTF-8");
+ ctype_loc = setlocale (LC_CTYPE, NULL);
+ if (ctype_loc && strcmp (ctype_loc, "C") == 0)
+ {
+ setlocale (LC_CTYPE, "C.utf8");
+ ctype_loc = setlocale (LC_CTYPE, NULL);
+ if (ctype_loc && strcmp (ctype_loc, "C") == 0)
+ setlocale (LC_CTYPE, "UTF-8");
+ }
+ }
+
/* If backtrace is required, we set signal handlers on the POSIX
2001 signals with core action. */
if (compile_options.backtrace)