summaryrefslogtreecommitdiff
path: root/locale.c
diff options
context:
space:
mode:
authorKarl Williamson <khw@cpan.org>2022-10-04 20:39:06 -0600
committerKarl Williamson <khw@cpan.org>2022-10-10 13:12:22 -0600
commit4f50c78e42b21d08f83148eff2ad27a569153eb6 (patch)
treec95643afb897f0a29e27349ba3261ba9e0ce6c9b /locale.c
parent5c686f46a71fe960e9455ae428b50955d6c6fdb1 (diff)
downloadperl-4f50c78e42b21d08f83148eff2ad27a569153eb6.tar.gz
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.
Diffstat (limited to 'locale.c')
-rw-r--r--locale.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/locale.c b/locale.c
index 55936d6277..c0d2185d3f 100644
--- a/locale.c
+++ b/locale.c
@@ -2497,7 +2497,7 @@ S_new_collate(pTHX_ const char *newcoll)
wchar_t *
S_Win_byte_string_to_wstring(const UINT code_page, const char * byte_string)
{
- wchar_t *wstring;
+ /* Caller must arrange to free the returned string */
int req_size = MultiByteToWideChar(code_page, 0, byte_string, -1, NULL, 0);
if (! req_size) {
@@ -2505,6 +2505,7 @@ S_Win_byte_string_to_wstring(const UINT code_page, const char * byte_string)
return NULL;
}
+ wchar_t *wstring;
Newx(wstring, req_size, wchar_t);
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)
char *
S_Win_wstring_to_byte_string(const UINT code_page, const wchar_t * wstring)
{
+ /* Caller must arrange to free the returned string */
int req_size =
WideCharToMultiByte(code_page, 0, wstring, -1, NULL, 0, NULL, NULL);
@@ -2547,6 +2549,10 @@ S_wrap_wsetlocale(pTHX_ const int category, const char *locale)
{
PERL_ARGS_ASSERT_WRAP_WSETLOCALE;
+ /* Calls _wsetlocale(), converting the parameters/return to/from
+ * Perl-expected forms as if plain setlocale() were being called instead.
+ */
+
const wchar_t * wlocale = NULL;
if (locale) {
@@ -2555,16 +2561,13 @@ S_wrap_wsetlocale(pTHX_ const int category, const char *locale)
return NULL;
}
}
- else {
- wlocale = NULL;
- }
const wchar_t * wresult = _wsetlocale(category, wlocale);
Safefree(wlocale);
if (! wresult) {
- return NULL;
- }
+ return NULL;
+ }
const char * result = Win_wstring_to_utf8_string(wresult);
SAVEFREEPV(result); /* is there something better we can do here? */