Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 15 Jul 2007 08:00:15 GMT
From:      Christoph Mallon <christoph.mallon@gmx.de>
To:        freebsd-standards@FreeBSD.org
Subject:   Re: kern/114578: [libc] wide character printing using swprintf(dst,  n, "%ls", txt) fails depending on LC_CTYPE
Message-ID:  <200707150800.l6F80FWt026610@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

The following reply was made to PR kern/114578; it has been noted by GNATS.

From: Christoph Mallon <christoph.mallon@gmx.de>
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/114578: [libc] wide character printing using swprintf(dst,
 n, "%ls", txt) fails depending on LC_CTYPE
Date: Sun, 15 Jul 2007 09:58:18 +0200

 Here is a simplified example:
 
 #include <locale.h>
 #include <stdio.h>
 #include <wchar.h>
 
 static const wchar_t txt[] = { 0x41C, 0x43D, 0x440, 0 }; // "Mir" in 
 cyrillic
 
 int main(void)
 {
    wchar_t str[4];
    int ret;
 
    setlocale(LC_CTYPE, "C");
    ret = swprintf(str, sizeof(str) / sizeof(*str), txt);
    printf("%d\n", ret);
 
    return 0;
 }
 
 Only a format string is used here. The call to swprintf() fails here, 
 too,  and -1 is returned. The POSIX standard (and ANSI C99, too, though 
 with slightly different wording) say this: "The format is composed of 
 zero or more directives: ordinary wide-characters, which are simply 
 copied to the output stream" (from 
 http://www.opengroup.org/onlinepubs/009695399/functions/swprintf.html , 
 section DESCRIPTION, second clause). So even copying the ordinary 
 wide-characters from the format string fails.



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200707150800.l6F80FWt026610>