In iOS, if I use vswprintf with a non-western locale, it will fail and return -1.
However, if I set the locale correctly it will write properly.
Why is this? Any ideas?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Strangely, the implementation of
vswprintfon iOS converts the wide string arguments it’s given to narrow strings and then converts the result back to a wide string (I had to debug this issue once). If your wide strings contain non-ASCII characters in them, then this is a lossy conversion, and only certain characters can be successfully converted.The exact set of non-ASCII characters which can be converted depends on the current locale setting. If you try to pass in unsupported characters, then
vswprintfwill fail by returning-1and settingerrnoto the errorEILSEQ(illegal multibyte sequence).On Mac OS X, at least, you can get around this by switching to a UTF-8 locale, e.g.:
However, this doesn’t appear to work on iOS, so if you need to be able to
vswprintfall characters without knowing the locale in advance, I’m afraid you’re out of luck unless you reimplementvswprintfyourself.