-3

I know there are many questions already asked on this topic but I am facing a very unusual situation here.

I am working in Centos. My application reads some data in wchar_t and converts in multibyte (UTF-8 encoding) and fills the char buffer in a google proto message and sends to another application.

The other application converts it again to wide string and displays it to user. I am using wcstombs for the conversion. My locale is "en_US.UTF-8".

For some strings it is working fine. I am facing issue in one particular wide string (maybe there are several others) in which wcstombs returns -1. Error number is set to 84 (Invalid or incomplete multibyte or wide character).

The problem is, when I am running my application through eclipse, the conversion is successful but when my application is run from root (as a service), the conversion fails.

Same string conversion is successful in windows using widechartomultibyte API.

I am not able to understand why this is happening.

Hope the experts can help me out.

EDIT

My Wide string is L"\006£æ?Jÿ" which when converted and displayed to user becomes as the imageenter image description here

Garfield
  • 175
  • 7
  • 17
  • It might help 'the experts' if you include the string that is failing. – Mark Jansen Jul 29 '15 at 11:06
  • 1
    When you say _locale is "en_US.UTF-8"_, do you mean that's the value of the environment `$LC_ALL` or `$LANG` or something? Did you call `setlocale`? – Useless Jul 29 '15 at 11:10
  • My wide string is L"\006£æ?Jÿ" My locale setting for root is: [root@apollo users]# locale LANG=en_US.UTF-8 LC_CTYPE="en_US.UTF-8" LC_NUMERIC="en_US.UTF-8" LC_TIME="en_US.UTF-8" LC_COLLATE="en_US.UTF-8" LC_MONETARY="en_US.UTF-8" LC_MESSAGES="en_US.UTF-8" LC_PAPER="en_US.UTF-8" LC_NAME="en_US.UTF-8" LC_ADDRESS="en_US.UTF-8" LC_TELEPHONE="en_US.UTF-8" LC_MEASUREMENT="en_US.UTF-8" LC_IDENTIFICATION="en_US.UTF-8" LC_ALL= – Garfield Jul 29 '15 at 11:27
  • The locale for root is often not the same as the locale for normal users. Depending on where exactly your locale for root is set, your services may or may not be subject to it. – n. m. could be an AI Jul 29 '15 at 11:52

1 Answers1

0

L"\006" doesn't appear to be a valid unicode string (neither in UTF-16 nor in UTF-32). I agree with wcstombs, there's no corresponding UTF-8 sequence.

I suspect you didn't use WC_ERR_INVALID_CHARS on Windows. That would catch the same error.

MSalters
  • 173,980
  • 10
  • 155
  • 350
  • I also suspected the same but when I ran my coed with string L"Jÿ", it is still returning same error. It is able to convert "J" but not the other character. In Windows, I have used WideCharToMultiByte(CP_UTF8, 0, wstring.c_str(), -1, buffer, 255, NULL, NULL); and it is working fine. What I am not able to understand or debug is why same string in Linux, when run from eclipse works fine but fails when run as a service. – Garfield Jul 30 '15 at 06:42