Ingo Schwarze <schwa...@usta.de> writes:

[...]

> When fputwc(3) encounters an encoding error, it neglects to set the
> error indicator, just like fgetwc(3) did before i fixed it today.
> Setting the error indicator is required by the manual and by the
> standard.

Hmm, the C standard and POSIX have slightly different texts regarding
this.

Quoting POSIX-2013:
-->8--
  RETURN VALUE

    Upon successful completion, fputwc() shall return wc. Otherwise, it
    shall return WEOF, the error indicator for the stream shall be set,
    [CX] and errno shall be set to indicate the error.
--<8--

Quoting the C99 draft, section 7.24.3.3:
--8<--
Returns

3 The fputwc function returns the wide character written. If a write
error occurs, the error indicator for the stream is set and fputwc
returns WEOF. If an encoding error occurs, the value of the macro EILSEQ
is stored in errno and fputwc returns WEOF.
-->8--

Note that the C11 draft has the same text.

So, the C standard doesn't say that the error indicator should be set on
the FILE in case of an encoding error, it only speaks about errno being
set to EILSEQ.  I'd say that we should follow the C standard here -
after all "This volume of POSIX.1-2008 defers to the ISO C standard".

The same can be said about the fgetwc(3) diff that was recently
committed, and for which I gave you an ok.

> Instead, it overrides errno again.  That's pointless because
> wcrtomb(3) already did that, and is required to do so by the standard.
> It is even slightly dangerous because it might hide internal coding
> errors in libc.  For example, if libc would ever neglect to initialize
> the state object correctly, wcrtomb(3) might fail with EINVAL.
> That should NOT be plastered over by setting errno to EILSEQ.

I agree that errno doesn't need to be overriden, but please leave _flags
alone.

[...]

> Index: fputwc.c
> ===================================================================
> RCS file: /cvs/src/lib/libc/stdio/fputwc.c,v
> retrieving revision 1.6
> diff -u -p -r1.6 fputwc.c
> --- fputwc.c  1 Oct 2015 02:32:07 -0000       1.6
> +++ fputwc.c  24 Dec 2015 21:01:10 -0000
> @@ -62,7 +62,7 @@ __fputwc_unlock(wchar_t wc, FILE *fp)
>  
>       size = wcrtomb(buf, wc, st);
>       if (size == (size_t)-1) {
> -             errno = EILSEQ;
> +             fp->_flags |= __SERR;
>               return WEOF;
>       }
>  


-- 
jca | PGP : 0x1524E7EE / 5135 92C1 AD36 5293 2BDF  DDCC 0DFA 74AE 1524 E7EE

Reply via email to