From b4dc51b39a386ce40c37df5c28c9b1540965e5f3 Mon Sep 17 00:00:00 2001 From: Oliver Tappe Date: Sun, 23 Jun 2013 11:45:38 +0200 Subject: [PATCH] Fix behaviour of towlower(), towupper() and towctrans(): * all those functions need to return the given wc unchanged in case of error, not 0 * towctrans() didn't actually look at the requested transition, but always acted as if _ISlower was given --- src/system/libroot/posix/locale/wctype.cpp | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/system/libroot/posix/locale/wctype.cpp b/src/system/libroot/posix/locale/wctype.cpp index 248079c91c..af0c59f160 100644 --- a/src/system/libroot/posix/locale/wctype.cpp +++ b/src/system/libroot/posix/locale/wctype.cpp @@ -159,7 +159,7 @@ towlower(wint_t wc) if (gLocaleBackend == NULL) return tolower(wc); - wint_t result = 0; + wint_t result = wc; gLocaleBackend->ToWCTrans(wc, _ISlower, result); return result; @@ -172,7 +172,7 @@ towupper(wint_t wc) if (gLocaleBackend == NULL) return toupper(wc); - wint_t result = 0; + wint_t result = wc; gLocaleBackend->ToWCTrans(wc, _ISupper, result); return result; @@ -182,12 +182,18 @@ towupper(wint_t wc) wint_t towctrans(wint_t wc, wctrans_t transition) { - if (gLocaleBackend == NULL) - return tolower(wc); + if (gLocaleBackend == NULL) { + if (transition == _ISlower) + return tolower(wc); + if (transition == _ISupper) + return toupper(wc); - wint_t result = 0; + __set_errno(EINVAL); + return wc; + } + + wint_t result = wc; status_t status = gLocaleBackend->ToWCTrans(wc, transition, result); - if (status != B_OK) __set_errno(EINVAL);