...
Code Block | ||||
---|---|---|---|---|
| ||||
#include <locale.h> #include <stdlib.h> size_tint utf8_to_ucs(wchar_t *ucs, size_t n, const char *utf8, size_t *size) { if (0 == size) { return -1; } setlocale(LC_CTYPE, "en_US.UTF-8"); return*size = mbstowcs(ucs, utf8, n); return 0; } |
Compliant Solution (setlocale()
)
...
Code Block | ||||
---|---|---|---|---|
| ||||
#include <locale.h> #include <stdlib.h> size_tint utf8_to_ucs(wchar_t *ucs, size_t n, const char *utf8, size_t *size) { if (0 == size) { return -1; } const char *save = setlocale(LC_CTYPE, "en_US.UTF-8"); if (NULL == save) { /* Propagate error to caller */ return (size_t)-1; } n*size = mbstowcs(ucs, utf8, n); if (NULL == setlocale(LC_CTYPE, save)) { n = (size_t)return -1; } return n0; } |
Noncompliant Code Example (signal()
)
...