#2038 freopen() fails on stdin

WSL
assigned
freopen (1)
Support
none
Unknown
False
2014-08-17
2013-09-09
Matt Heyse
No

I've believe I've found a bug. When piping data from one command to another stdin defaults to non-binary. This can destructively alter the data being passed. The fix on unix/llinux is to reopen stdin as binary using freopen(). However in MinGW it fails with the error "No such file or directory"

I'm attaching three demo programs to thoroughly show the bug. Each is commented at the top.

I belive I'm using the current version of MinGW

 C:\MinGW\forest\Bin-Stdin>gcc -v
 Using built-in specs.
 COLLECT_GCC=gcc
 COLLECT_LTO_WRAPPER=c:/mingw/bin/../libexec/gcc/mingw32/4.6.2/lto-wrapper.exe
 Target: mingw32
 Configured with: ../gcc-4.6.2/configure --enable-languages=c,c++,ada,fortran,objc,obj-c++ --disable-sjlj-exceptions --with-dwarf2 --enable-shared --enable-libgomp --disable-win32-registry --enable-libstdcxx-debug --enable-version-specific-runtime-libs --build=mingw32 --prefix=/mingw
 Thread model: win32
 gcc version 4.6.2 (GCC)

ld

C:\MinGW\forest\Bin-Stdin>ld -v
GNU ld (GNU Binutils) 2.22

On

  Mirosoft Windows XP SP3
  cmd.exe shell included in the OS
1 Attachments

Discussion

  • Matt Heyse

    Matt Heyse - 2013-09-09

    Also just to point out, this is not a limitation of the OS or Shell. The Native "type" command passes binary data just fine.

    Here is file 2

     
  • Matt Heyse

    Matt Heyse - 2013-09-09

    Here is the file that fails to work properly (bug example)

     
  • Earnie Boyd

    Earnie Boyd - 2013-09-09

    Firstly, there is no use in comparing what happens on linux/unix as to what happens in Windows. If you compare what happens between MSVC versus GCC that is a worthy comparison.

    Secondly, it is Microsoft supplying the code for the function, see MSDN for reference to the most current release from MSVC. I'll try to test your programs sometime next week, this week I have not time.

     
  • Earnie Boyd

    Earnie Boyd - 2013-09-09
    • labels: --> freopen
    • status: unread --> assigned
    • assigned_to: Earnie Boyd
    • Group: OTHER --> WSL
    • Type: Bug --> Support
     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks