[Bug stdio/20677] perror() changes orientation of stream when it is redirected
igor.liferenko at gmail dot com
sourceware-bugzilla@sourceware.org
Mon Oct 17 08:17:00 GMT 2016
https://sourceware.org/bugzilla/show_bug.cgi?id=20677
--- Comment #8 from Igor Liferenko <igor.liferenko at gmail dot com> ---
This little program demonstrates that the idea with "write()" works perfectly:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
int main(void)
{
int fd;
int fd2;
char buf[200];
int n;
char fname[] = "/tmp/tst-perror.XXXXXX";
fd = mkstemp (fname);
fclose (stderr);
dup2 (fd, 2);
stderr = fdopen (2, "w");
fd2 = fileno(stderr);
char *s = "this is a test\n";
n = write(fd2, s, strlen(s));
fprintf(stderr, "multibyte string\n");
fclose (stderr);
lseek (fd, 0, SEEK_SET);
n = read (fd, buf, sizeof (buf));
printf("%.*s", (int) n, buf);
close (fd);
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