@@ -2728,9 +2728,27 @@ Perl_my_strerror(pTHX_ const int errnum)
2728
2728
2729
2729
const bool within_locale_scope = IN_LC (LC_MESSAGES );
2730
2730
2731
- # ifdef USE_POSIX_2008_LOCALE
2731
+ # if defined(HAS_POSIX_2008_LOCALE ) && defined(HAS_STRERROR_L )
2732
+
2733
+ /* This function is trivial if we have strerror_l() */
2734
+
2735
+ if (within_locale_scope ) {
2736
+ errstr = strerror (errnum );
2737
+ }
2738
+ else {
2739
+ errstr = strerror_l (errnum , PL_C_locale_obj );
2740
+ }
2741
+
2742
+ errstr = savepv (errstr );
2743
+
2744
+ # else /* Doesn't have strerror_l(). */
2745
+
2746
+ # ifdef USE_POSIX_2008_LOCALE
2747
+
2732
2748
locale_t save_locale = NULL ;
2733
- # else
2749
+
2750
+ # else
2751
+
2734
2752
char * save_locale = NULL ;
2735
2753
bool locale_is_C = FALSE;
2736
2754
@@ -2739,7 +2757,7 @@ Perl_my_strerror(pTHX_ const int errnum)
2739
2757
* setlocale() ) */
2740
2758
LOCALE_LOCK ;
2741
2759
2742
- # endif
2760
+ # endif
2743
2761
2744
2762
DEBUG_Lv (PerlIO_printf (Perl_debug_log ,
2745
2763
"my_strerror called with errnum %d\n" , errnum ));
@@ -2761,7 +2779,7 @@ Perl_my_strerror(pTHX_ const int errnum)
2761
2779
"uselocale returned 0x%p\n" , save_locale ));
2762
2780
}
2763
2781
2764
- # else /* Not thread-safe build */
2782
+ # else /* Not thread-safe build */
2765
2783
2766
2784
save_locale = setlocale (LC_MESSAGES , NULL );
2767
2785
if (! save_locale ) {
@@ -2781,7 +2799,7 @@ Perl_my_strerror(pTHX_ const int errnum)
2781
2799
}
2782
2800
}
2783
2801
2784
- # endif
2802
+ # endif
2785
2803
2786
2804
} /* end of ! within_locale_scope */
2787
2805
else {
@@ -2807,7 +2825,7 @@ Perl_my_strerror(pTHX_ const int errnum)
2807
2825
}
2808
2826
}
2809
2827
2810
- # else
2828
+ # else
2811
2829
2812
2830
if (save_locale && ! locale_is_C ) {
2813
2831
if (! setlocale (LC_MESSAGES , save_locale )) {
@@ -2820,7 +2838,8 @@ Perl_my_strerror(pTHX_ const int errnum)
2820
2838
2821
2839
LOCALE_UNLOCK ;
2822
2840
2823
- # endif
2841
+ # endif
2842
+ # endif /* End of doesn't have strerror_l */
2824
2843
#endif /* End of does have locale messages */
2825
2844
2826
2845
#ifdef DEBUGGING
0 commit comments