Skip to content

Commit

Permalink
locale.c: Refactor some #if clauses
Browse files Browse the repository at this point in the history
This moves all the handling of the case where there are no locale
messages, instead of splitting it up across long stretches of
conditionally compiled code.  This code is essentially trivial, and seen
to be so when it isn't split up; this prepares for the next commit.

The final return of the function is still split off so that all branches
go through it, and the debugging code adjacent to it.
  • Loading branch information
khwilliamson committed Aug 13, 2017
1 parent 6affbbf commit 5277094
Showing 1 changed file with 13 additions and 15 deletions.
28 changes: 13 additions & 15 deletions locale.c
Original file line number Diff line number Diff line change
Expand Up @@ -2715,13 +2715,18 @@ Perl_my_strerror(pTHX_ const int errnum)
* to the C locale */

char *errstr;
dVAR;

#ifdef USE_LOCALE_MESSAGES /* If platform doesn't have messages category, we
don't do any switching to the C locale; we just
use whatever strerror() returns */
const bool within_locale_scope = IN_LC(LC_MESSAGES);
#ifndef USE_LOCALE_MESSAGES

dVAR;
/* If platform doesn't have messages category, we don't do any switching to
* the C locale; we just use whatever strerror() returns */

errstr = savepv(Strerror(errnum));

#else /* Has locale messages */

const bool within_locale_scope = IN_LC(LC_MESSAGES);

# ifdef USE_POSIX_2008_LOCALE
locale_t save_locale = NULL;
Expand Down Expand Up @@ -2784,18 +2789,9 @@ Perl_my_strerror(pTHX_ const int errnum)
__FILE__, __LINE__));
}

#endif

DEBUG_Lv(PerlIO_printf(Perl_debug_log,
"Any locale change has been done; about to call Strerror\n"));
errstr = Strerror(errnum);
if (errstr) {

errstr = savepv(errstr);
SAVEFREEPV(errstr);
}

#ifdef USE_LOCALE_MESSAGES
errstr = savepv(Strerror(errnum));

if (! within_locale_scope) {
errno = 0;
Expand Down Expand Up @@ -2825,6 +2821,7 @@ Perl_my_strerror(pTHX_ const int errnum)
LOCALE_UNLOCK;

# endif
#endif /* End of does have locale messages */

#ifdef DEBUGGING

Expand All @@ -2836,6 +2833,7 @@ Perl_my_strerror(pTHX_ const int errnum)

#endif

SAVEFREEPV(errstr);
return errstr;
}

Expand Down

0 comments on commit 5277094

Please sign in to comment.