perror() changes orientation of non-oriented stderr when it is redirected
Igor Liferenko
igor.liferenko@gmail.com
Mon Jan 30 03:13:00 GMT 2017
Hi all,
I would like to recompile glibc locally with this patch:
https://sourceware.org/bugzilla/attachment.cgi?id=9580
(this patch does not bring any incompatibility with existing programs)
This patch fixes a small bug, which can be seen by compiling the
following program and then running:
$ ./a.out 2>/dev/null
The output is incorrect:
initial fwide: 0
fwide: -1
After applying the patch, the output becomes correct:
initial fwide: 0
fwide: 0
There are two issues with this patch, and I need help to figure them out.
1) what to do if "__write()" fails?
2) may "if (_IO_ferror_unlocked(fp))" test be safely deleted?
See also https://sourceware.org/bugzilla/show_bug.cgi?id=20677
Regards,
Igor
=================================
#include <stdio.h>
#include <wchar.h>
#include <errno.h>
int main(void)
{
printf("initial fwide: %d\n", fwide(stderr, 0));
errno = EINVAL;
perror(""); /* note, that prior to this call stderr was not oriented */
printf("fwide: %d\n", fwide(stderr, 0));
return 0;
}
More information about the Libc-help
mailing list