fgetwc returns various errors when it shouldn't

Bug #307987 reported by Roland Illig
2
Affects Status Importance Assigned to Milestone
glibc (Ubuntu)
New
Undecided
Unassigned

Bug Description

$ cat wcw.c
#define _GNU_SOURCE

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

int
main(void)
{
        wint_t c;

        if (!setlocale(LC_CTYPE, "")) {
                perror("setlocale");
                exit(EXIT_FAILURE);
        }

        while ((errno = 0, c = fgetwc(stdin)) != WEOF) {
                printf("U+%04x has width %d\n", (unsigned)c, wcwidth(c));
        }

        if (errno != 0) {
                fprintf(stderr, "errno = %d\n", errno);
                perror("fgetwc");
                exit(EXIT_FAILURE);
        }
        return 0;
}

$ cc -Wall -W wcw.c -o wcw
$ ./wcw < empty
$ ./wcw < /dev/null
errno = 25
fgetwc: Inappropriate ioctl for device
$ cat /dev/null | ./wcw
errno = 29
fgetwc: Illegal seek

On the other hand, on Solaris 10, I get the following behavior, which lets me distinguish EOF from errors:

$ ./wcw < empty
$ ./wcw < /de
$ ./wcw < /dev/null
$ cat empty | ./wcw

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.