diff --git a/libgfortran/io/io.h b/libgfortran/io/io.h index ab4a103787c..b4a811384c9 100644 --- a/libgfortran/io/io.h +++ b/libgfortran/io/io.h @@ -52,8 +52,12 @@ struct format_data; typedef struct fnode fnode; struct gfc_unit; -#ifdef HAVE_NEWLOCALE -/* We have POSIX 2008 extended locale stuff. */ +#if defined (HAVE_FREELOCALE) && defined (HAVE_NEWLOCALE) \ + && defined (HAVE_USELOCALE) +/* We have POSIX 2008 extended locale stuff. We only choose to use it + if all the functions required are present as some systems, e.g. NetBSD + do not have `uselocale'. */ +#define HAVE_POSIX_2008_LOCALE extern locale_t c_locale; internal_proto(c_locale); #else @@ -562,7 +566,7 @@ typedef struct st_parameter_dt char *line_buffer; struct format_data *fmt; namelist_info *ionml; -#ifdef HAVE_NEWLOCALE +#ifdef HAVE_POSIX_2008_LOCALE locale_t old_locale; #endif /* Current position within the look-ahead line buffer. */ diff --git a/libgfortran/io/transfer.c b/libgfortran/io/transfer.c index dc18bc34b32..c36d8bca808 100644 --- a/libgfortran/io/transfer.c +++ b/libgfortran/io/transfer.c @@ -3410,7 +3410,7 @@ data_transfer_init_worker (st_parameter_dt *dtp, int read_flag) if (dtp->u.p.current_unit->flags.form == FORM_FORMATTED) { -#ifdef HAVE_USELOCALE +#ifdef HAVE_POSIX_2008_LOCALE dtp->u.p.old_locale = uselocale (c_locale); #else __gthread_mutex_lock (&old_locale_lock); @@ -4243,7 +4243,7 @@ finalize_transfer (st_parameter_dt *dtp) } } -#ifdef HAVE_USELOCALE +#ifdef HAVE_POSIX_2008_LOCALE if (dtp->u.p.old_locale != (locale_t) 0) { uselocale (dtp->u.p.old_locale); diff --git a/libgfortran/io/unit.c b/libgfortran/io/unit.c index a3b0656cb90..faf62997b5e 100644 --- a/libgfortran/io/unit.c +++ b/libgfortran/io/unit.c @@ -114,7 +114,7 @@ static char stdout_name[] = "stdout"; static char stderr_name[] = "stderr"; -#ifdef HAVE_NEWLOCALE +#ifdef HAVE_POSIX_2008_LOCALE locale_t c_locale; #else /* If we don't have POSIX 2008 per-thread locales, we need to use the @@ -586,7 +586,7 @@ init_units (void) { gfc_unit *u; -#ifdef HAVE_NEWLOCALE +#ifdef HAVE_POSIX_2008_LOCALE c_locale = newlocale (0, "C", 0); #else #ifndef __GTHREAD_MUTEX_INIT @@ -803,7 +803,7 @@ close_units (void) free (newunits); -#ifdef HAVE_FREELOCALE +#ifdef HAVE_POSIX_2008_LOCALE freelocale (c_locale); #endif } diff --git a/libgfortran/runtime/error.c b/libgfortran/runtime/error.c index ff6b852a07c..a401dbad164 100644 --- a/libgfortran/runtime/error.c +++ b/libgfortran/runtime/error.c @@ -272,7 +272,7 @@ gf_strerror (int errnum, p = strerror (errnum); return p; #elif defined(HAVE_STRERROR_R) -#ifdef HAVE_USELOCALE +#ifdef HAVE_POSIX_2008_LOCALE /* Some targets (Darwin at least) have the POSIX 2008 extended locale functions, but not strerror_l. So reset the per-thread locale here. */