public inbox for glibc-bugs@sourceware.org help / color / mirror / Atom feed
From: "lizhijian at cn dot fujitsu.com" <sourceware-bugzilla@sourceware.org> To: glibc-bugs@sourceware.org Subject: [Bug libc/15589] freopen would close oldfd even though oldfd is same as newfd Date: Thu, 06 Jun 2013 05:53:00 -0000 [thread overview] Message-ID: <bug-15589-131-J4MNj0fhtP@http.sourceware.org/bugzilla/> (raw) In-Reply-To: <bug-15589-131@http.sourceware.org/bugzilla/> http://sourceware.org/bugzilla/show_bug.cgi?id=15589 --- Comment #1 from lizhijian <lizhijian at cn dot fujitsu.com> --- A simple C program(freopen-test.c) to reproduce this problem. #include <stdio.h> #include <errno.h> #include <string.h> #include <sys/stat.h> int main(void) { char *file1 = "./file1"; char *file2 = "./file2"; FILE *fp1, *fp2; struct stat stat_buf; if((fp1 = freopen(file1, "r", stdin)) == NULL) printf("[E+] freopen error(%s)\n", strerror(errno)); if (fstat(fileno(stdin), &stat_buf) == 0) { printf("[S+] close stdin\n"); close(0); //close stdin } if (fstat(fileno(stdin), &stat_buf) == -1) { printf("[S+] stat return error(%s)\n", strerror(errno)); if ((fp2 = freopen(file2, "r", stdin)) == NULL) { printf("[E+] freopen return error(%s)\n",strerror(errno)); return -1; } } if (fstat(fileno(fp2), &stat_buf) == -1) { printf("[E+] freopen return success, but the newfd was closed\n"); return -1; } fclose(fp1); fclose(fp2); printf("[S+] freopen test PASS\n"); } ------------------------ # gcc freopen-test.c -o freopen-test # touch file1 file2 # ./freopen-test [E+] freopen error(No such file or directory) [S+] stat return error(Bad file descriptor) [E+] freopen return error(No such file or directory) # rpm -q glibc glibc-2.16-29.el7.x86_64 -- You are receiving this mail because: You are on the CC list for the bug.
next prev parent reply other threads:[~2013-06-06 5:53 UTC|newest] Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top 2013-06-06 5:50 [Bug libc/15589] New: " lizhijian at cn dot fujitsu.com 2013-06-06 5:53 ` lizhijian at cn dot fujitsu.com [this message] 2013-06-06 5:56 ` [Bug libc/15589] " lizhijian at cn dot fujitsu.com 2013-06-14 4:03 ` lizhijian at cn dot fujitsu.com 2014-06-13 15:10 ` fweimer at redhat dot com 2015-08-22 20:36 ` [Bug stdio/15589] " jsm28 at gcc dot gnu.org
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-15589-131-J4MNj0fhtP@http.sourceware.org/bugzilla/ \ --to=sourceware-bugzilla@sourceware.org \ --cc=glibc-bugs@sourceware.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).