Skip to content

Commit 4f50c78

Browse files
committed
locale.c: Add comments/white space; slight tidying
C99 allows declarations to be closer to their first use. This also removes a redundant conditional that would set a variable to what it already was initialized to.
1 parent 5c686f4 commit 4f50c78

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

locale.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2497,14 +2497,15 @@ S_new_collate(pTHX_ const char *newcoll)
24972497
wchar_t *
24982498
S_Win_byte_string_to_wstring(const UINT code_page, const char * byte_string)
24992499
{
2500-
wchar_t *wstring;
2500+
/* Caller must arrange to free the returned string */
25012501

25022502
int req_size = MultiByteToWideChar(code_page, 0, byte_string, -1, NULL, 0);
25032503
if (! req_size) {
25042504
errno = EINVAL;
25052505
return NULL;
25062506
}
25072507

2508+
wchar_t *wstring;
25082509
Newx(wstring, req_size, wchar_t);
25092510

25102511
if (! MultiByteToWideChar(code_page, 0, byte_string, -1, wstring, req_size))
@@ -2522,6 +2523,7 @@ S_Win_byte_string_to_wstring(const UINT code_page, const char * byte_string)
25222523
char *
25232524
S_Win_wstring_to_byte_string(const UINT code_page, const wchar_t * wstring)
25242525
{
2526+
/* Caller must arrange to free the returned string */
25252527

25262528
int req_size =
25272529
WideCharToMultiByte(code_page, 0, wstring, -1, NULL, 0, NULL, NULL);
@@ -2547,6 +2549,10 @@ S_wrap_wsetlocale(pTHX_ const int category, const char *locale)
25472549
{
25482550
PERL_ARGS_ASSERT_WRAP_WSETLOCALE;
25492551

2552+
/* Calls _wsetlocale(), converting the parameters/return to/from
2553+
* Perl-expected forms as if plain setlocale() were being called instead.
2554+
*/
2555+
25502556
const wchar_t * wlocale = NULL;
25512557

25522558
if (locale) {
@@ -2555,16 +2561,13 @@ S_wrap_wsetlocale(pTHX_ const int category, const char *locale)
25552561
return NULL;
25562562
}
25572563
}
2558-
else {
2559-
wlocale = NULL;
2560-
}
25612564

25622565
const wchar_t * wresult = _wsetlocale(category, wlocale);
25632566
Safefree(wlocale);
25642567

25652568
if (! wresult) {
2566-
return NULL;
2567-
}
2569+
return NULL;
2570+
}
25682571

25692572
const char * result = Win_wstring_to_utf8_string(wresult);
25702573
SAVEFREEPV(result); /* is there something better we can do here? */

0 commit comments

Comments
 (0)