Hottest Free Downloads - DownloadPipe.com Over 197,000 downloads! Bookmark Now!
DownloadPipe.com - New Downloads Every Minute
 SEARCH:
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

correct behaviour of mbstowcs function

 
   Mac (Home) -> Programmer Code RSS
Next:  What library to link against?  
Author Message
Hartwig Wiesmann

External


Since: Jan 05, 2006
Posts: 9



(Msg. 1) Posted: Thu Jan 05, 2006 11:40 pm
Post subject: correct behaviour of mbstowcs function
Archived from groups: comp>sys>mac>programmer>codewarrior (more info?)

Hi!

It seems to be that the MSL lib implements the mbstowcs function
differently from Apple's implementation in case the first pointer is NULL.
Apple's implementation seems to return the length of the "in"-string
while MSL always returns 0. When looking at Apple's man pages even
(size_t) -1 should be returned.

Now, what is the right functionality?

Hartwig

PS: man pages from Apple to mbstowc

#include <stdlib.h>

size_t
mbstowcs(wchar_t * restrict wcstring, const char * restrict mbstring,
size_t nwchars);

#include <xlocale.h>

size_t
mbstowcs_l(wchar_t * restrict wcstring, const char * restrict
mbstring,
size_t nwchars, locale_t loc);

DESCRIPTION
The mbstowcs() function converts a multibyte character string mbstring
beginning in the initial conversion state into a wide character string
wcstring. No more than nwchars wide characters are stored. A
terminat-terminating
ing null wide character is appended if there is room.

While the mbstowcs() function uses the current locale, the
mbstowcs_l()
function may be passed a locale directly. See xlocale(3) for more
infor-information.
mation.

RETURN VALUES
The mbstowcs() function returns the number of wide characters
converted,
not counting any terminating null wide character, or -1 if an invalid
multibyte character was encountered.

ERRORS
The mbstowcs() function will fail if:

[EILSEQ] An invalid multibyte sequence was detected.

[EINVAL] The conversion state is invalid.
Back to top
Login to vote
Alwyn

External


Since: Oct 28, 2005
Posts: 27



(Msg. 2) Posted: Fri Jan 06, 2006 2:27 am
Post subject: Re: correct behaviour of mbstowcs function [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

In article <43bd9ff7$0$31409$dbd4b001@news.wanadoo.nl>,
Hartwig Wiesmann <hartwig.wiesmann.TakeThisOut@wanadoo.nl> wrote:
>
> It seems to be that the MSL lib implements the mbstowcs function
> differently from Apple's implementation in case the first pointer is NULL.
> Apple's implementation seems to return the length of the "in"-string
> while MSL always returns 0. When looking at Apple's man pages even
> (size_t) -1 should be returned.

Where does it say that?

> Now, what is the right functionality?

I haven't got the C99 specification to hand, but this is the relevant
part of the Single Unix definition for the function:

> RETURN VALUE
> If an invalid character is encountered, mbstowcs() returns (size_t)-1 and may
> set errno to indicate the error. Otherwise, mbstowcs() returns the number of
> the array elements modified (or required if pwcs is null), not including a
> terminating 0 code, if any. The array will not be zero-terminated if the
> value returned is n.

<http://www.opengroup.org/onlinepubs/007908799/xsh/mbstowcs.html>

Note the words in brackets: 'or required if pwcs is null'.


Alwyn
Back to top
Login to vote
Hartwig Wiesmann

External


Since: Jan 05, 2006
Posts: 9



(Msg. 3) Posted: Fri Jan 06, 2006 6:39 pm
Post subject: Re: correct behaviour of mbstowcs function [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Hi Alwyn,

Apple says:
The mbstowcs() function returns the number of wide characters converted,
not counting any terminating null wide character, or -1 if an invalid
multibyte character was encountered.

Sorry, misread. Actually zero should be returned as no characters are
converted when the wchar* pointer is NULL.
Your definition would return the length of the byte character sequence.

MSL always returns 0 when a NULL pointer is passed to mbstowcs.

Hartwig


Alwyn wrote:

> In article <43bd9ff7$0$31409$dbd4b001@news.wanadoo.nl>,
> Hartwig Wiesmann <hartwig.wiesmann DeleteThis @wanadoo.nl> wrote:
>
>>It seems to be that the MSL lib implements the mbstowcs function
>>differently from Apple's implementation in case the first pointer is NULL.
>>Apple's implementation seems to return the length of the "in"-string
>>while MSL always returns 0. When looking at Apple's man pages even
>>(size_t) -1 should be returned.
>
>
> Where does it say that?
>
>
>>Now, what is the right functionality?
>
>
> I haven't got the C99 specification to hand, but this is the relevant
> part of the Single Unix definition for the function:
>
>
>>RETURN VALUE
>>If an invalid character is encountered, mbstowcs() returns (size_t)-1 and may
>>set errno to indicate the error. Otherwise, mbstowcs() returns the number of
>>the array elements modified (or required if pwcs is null), not including a
>>terminating 0 code, if any. The array will not be zero-terminated if the
>>value returned is n.
>
>
> <http://www.opengroup.org/onlinepubs/007908799/xsh/mbstowcs.html>
>
> Note the words in brackets: 'or required if pwcs is null'.
>
>
> Alwyn
Back to top
Login to vote
Display posts from previous:   
Related Topics:
Bug in alloc.c? - I'm getting an infinite loop in alloc.c, which is located in MSL/MSL_C/MSL_Common/Src. This is with CW 9.5. The function is allocate_from_var_pools. There is a do/while loop that searches for a block with the required size to allocate a block of..

Multiply defined symbol: .bss - Hi, when trying to build a dll for Windows using CW9 on MacOS, I get an error message like: Link Error : Multiply defined symbol: .bss in files file1.cpp, file2.cpp The same message with the same filenames is repeated several times, but....

Where next? - Hi folks, All of my recent Mac coding has been Carbon C++, mostly using PowerPlant as a framework. As most of my clients are moving to X and CW's future is, shall we say, uncertain I'm wondering where to look for my future coding setup. I've dabbled....

Does mwcc work on Tiger? - Anybody using the comand line compilers on 10.4? When saving the following simple program as /tmp/x.cpp: int main() { double x = 0.5; return 0; } and trying to compile it with $ mwcc -c /tmp/x.cpp , I get the error message Error :....

Console app "file" selector - Hello, I feel like I've asked this before, but I did a search on the archives and came up short. I've got a console std c app that I'm compiling with CW. When it runs, it pops up a little menu where I can type in some command line arguments (for..
       Mac (Home) -> Programmer Code All times are: Pacific Time (US & Canada) (change)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You can edit your posts in this forum
You can delete your posts in this forum
You can vote in polls in this forum
Categories:
 Windows Forums
 Game Forums
 Linux Forums
  Mac Forums
 PDA Forums
 Mobile Forums
  Top  |  Store  |  RSS Feeds RSS  |  Data Feeds  |  Advertise  |  Submit  |  Bookmark  |  Newsletter  |  Contact