kern/114578: [libc] wide character printing using swprintf(dst, n, "%ls", txt) fails depending on LC_CTYPE

Christoph Mallon christoph.mallon at gmx.de
Sun Jul 15 08:00:15 UTC 2007


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

From: Christoph Mallon <christoph.mallon at gmx.de>
To: bug-followup at 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.


More information about the freebsd-standards mailing list