diff options
author | Karl Williamson <khw@cpan.org> | 2017-07-15 18:18:47 -0600 |
---|---|---|
committer | Karl Williamson <khw@cpan.org> | 2017-08-12 22:53:11 -0600 |
commit | 7aaa36b196e5a478a3d1bd32506797db7cebf0b2 (patch) | |
tree | 2f8e4e042a49b6061260a29d1350636449251805 | |
parent | 52770946b48e2fbf46e592f4c7273c83e949d89e (diff) | |
download | perl-7aaa36b196e5a478a3d1bd32506797db7cebf0b2.tar.gz |
locale.c: Use strerror_l if platform has it
strerror_l makes the my_strerror function trivial, as it doesn't have to
worry about critical sections, etc. Even on unthreaded perls, it avoids
having to change the current locale, and then change it back.
-rw-r--r-- | locale.c | 33 |
1 files changed, 26 insertions, 7 deletions
@@ -2728,9 +2728,27 @@ Perl_my_strerror(pTHX_ const int errnum) const bool within_locale_scope = IN_LC(LC_MESSAGES); -# ifdef USE_POSIX_2008_LOCALE +# if defined(HAS_POSIX_2008_LOCALE) && defined(HAS_STRERROR_L) + + /* This function is trivial if we have strerror_l() */ + + if (within_locale_scope) { + errstr = strerror(errnum); + } + else { + errstr = strerror_l(errnum, PL_C_locale_obj); + } + + errstr = savepv(errstr); + +# else /* Doesn't have strerror_l(). */ + +# ifdef USE_POSIX_2008_LOCALE + locale_t save_locale = NULL; -# else + +# else + char * save_locale = NULL; bool locale_is_C = FALSE; @@ -2739,7 +2757,7 @@ Perl_my_strerror(pTHX_ const int errnum) * setlocale() ) */ LOCALE_LOCK; -# endif +# endif DEBUG_Lv(PerlIO_printf(Perl_debug_log, "my_strerror called with errnum %d\n", errnum)); @@ -2761,7 +2779,7 @@ Perl_my_strerror(pTHX_ const int errnum) "uselocale returned 0x%p\n", save_locale)); } -# else /* Not thread-safe build */ +# else /* Not thread-safe build */ save_locale = setlocale(LC_MESSAGES, NULL); if (! save_locale) { @@ -2781,7 +2799,7 @@ Perl_my_strerror(pTHX_ const int errnum) } } -# endif +# endif } /* end of ! within_locale_scope */ else { @@ -2807,7 +2825,7 @@ Perl_my_strerror(pTHX_ const int errnum) } } -# else +# else if (save_locale && ! locale_is_C) { if (! setlocale(LC_MESSAGES, save_locale)) { @@ -2820,7 +2838,8 @@ Perl_my_strerror(pTHX_ const int errnum) LOCALE_UNLOCK; -# endif +# endif +# endif /* End of doesn't have strerror_l */ #endif /* End of does have locale messages */ #ifdef DEBUGGING |