[Bug stdio/17522] New: `fputws' errors out when writing wide characters to unbuffered stream

arjun.is at lostca dot se sourceware-bugzilla@sourceware.org
Wed Oct 29 15:57:00 GMT 2014


https://sourceware.org/bugzilla/show_bug.cgi?id=17522

            Bug ID: 17522
           Summary: `fputws' errors out when writing wide characters to
                    unbuffered stream
           Product: glibc
           Version: 2.21
            Status: NEW
          Severity: normal
          Priority: P2
         Component: stdio
          Assignee: unassigned at sourceware dot org
          Reporter: arjun.is at lostca dot se

I observed this bug when trying to modify libio/tst-fopenloc.c (which uses
fputws) to use test-skeleton.c (which un-buffers stdout).

When writing to an unbuffered stream, `fputws' seems to error out as soon as it
encounters a UTF-8 character that takes up more than one byte.

Reproducer: The below test case should print "Platform 9¾" to stdout and finish
successfully. It does not. fputws prints "Platform 9" then returns -1:

#include <locale.h>
#include <stdio.h>
#include <wchar.h>
#include <string.h>
#include <errno.h>

int
main (void)
{
  wchar_t buf[100] = L"Platform 9";
  FILE *fp;
  int r;

  setlocale (LC_ALL, "en_US.UTF-8");

  buf[10] = L'\xbe'; /* unicode code point for "3/4" */
  buf[11] = L'\n';
  buf[12] = L'\0';

  setvbuf (stdout, NULL, _IONBF, 0);

  if (fputws (buf, stdout) < 0)
    return 1;

  return 0;
}

-- 
You are receiving this mail because:
You are on the CC list for the bug.


More information about the Glibc-bugs mailing list