delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2007/10/23/06:43:25

X-Recipient: archive-cygwin AT delorie DOT com
X-Spam-Check-By: sourceware.org
Date: Tue, 23 Oct 2007 12:42:58 +0200
From: Corinna Vinschen <corinna-cygwin AT cygwin DOT com>
To: newlib AT sourceware DOT org
Cc: cygwin AT cygwin DOT com
Subject: Re: No space calculation in wcstombs?
Message-ID: <20071023104258.GA21700@calimero.vinschen.de>
Reply-To: newlib AT sourceware DOT org
Mail-Followup-To: newlib AT sourceware DOT org, cygwin AT cygwin DOT com
References: <E828DFE1-0E83-4500-A761-CEDC7944D3F0 AT spellbreaker DOT org>
MIME-Version: 1.0
In-Reply-To: <E828DFE1-0E83-4500-A761-CEDC7944D3F0@spellbreaker.org>
User-Agent: Mutt/1.5.16 (2007-06-09)
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Unsubscribe: <mailto:cygwin-unsubscribe-archive-cygwin=delorie DOT com AT cygwin DOT com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com

[Redirected to the newlib mailing list]

On Oct 23 11:52, Christoph Ender wrote:
> Hi all,
>
> when converting wchar_t*- to (mb)char*-Strings I've been
> so far using the wcstombs function in two steps: One call
> to length=wcstombs(NULL, *src, 0) in order to make the
> function return the space required for the dest string
> and one call wo wcstombs(*dest, *src, length) to actually
> convert the src string after allocating (length) bytes.
>
> I've just noticed that the first step does not work with
> cygwin and  I've attached a small example to demonstrate
> the problem. On a Linux- and Mac OS X-machine the return
> value is 26, on cygwin 0. Since wcstombs is supposed to be
> affected by the current locale setting I've set the locale
> to "C", but the result is still the same: cygwin always
> tries to do the actual converion (if the len parameter is
> not 0 there is a segfault) instead of measuring the space
> requirements.
>
> ----------8<----------8<----------8<----------8<----------
>
> #include <stdio.h>
> #include <wchar.h>
> #include <locale.h>
>
> int main(int argc, char *argv[])
> {
>   int result;
>   wchar_t s[] = L"abcdefghijklmnopqrstuvwxyz";
>
>   printf("Locale: %s\n", setlocale(LC_ALL, "C"));
>
>   result = wcstombs(NULL, s, 0);
>
>   printf("Required space: %d.\n", result);
>
>   return 0;
> }
>
> ----------8<----------8<----------8<----------8<----------
>
> What am I doing wrong here? Or is this actually a cygwin
> problem?

No, it's a newlib problem.  The wide character support in newlib
is somewhat rudimentary.  The reason is that newlib is mainly
targeting embedded systems which don't need full wchar support.

However, as this is an open source project, patches are always
welcome.


Corinna

-- 
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Project Co-Leader          cygwin AT cygwin DOT com
Red Hat

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019