This is the mail archive of the
glibc-bugs@sourceware.org
mailing list for the glibc project.
[Bug stdio/20677] perror() changes orientation of stream when it is redirected
- From: "igor.liferenko at gmail dot com" <sourceware-bugzilla at sourceware dot org>
- To: glibc-bugs at sourceware dot org
- Date: Mon, 17 Oct 2016 02:47:46 +0000
- Subject: [Bug stdio/20677] perror() changes orientation of stream when it is redirected
- Auto-submitted: auto-generated
- References: <bug-20677-131@http.sourceware.org/bugzilla/>
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.