From: cgf AT bbc DOT com (Christopher Faylor) Subject: Re: freopen bug? 18 Feb 1998 22:02:38 -0800 Message-ID: References: Reply-To: cgf AT bbc DOT com To: cygwin32-developers AT cygnus DOT com In article <199802190037 DOT QAA09366 AT skaro DOT cygnus DOT com>, Geoffrey Noer wrote: >Christopher Faylor wrote: >> >> Mumit Khan has indicated that he is having problems getting collect2 to >> work with EGCS due to an apparent bug in newlib's freopen. >> >> The problem is that freopen is apparently not preserving the fd of the >> stream that is operating on. > >I have committed this patch since it does fix the problem demonstrated >in your test program. However, I still have collect2 problems. > >//cpp.1 >#include > >list my_list01; > >--------------------------- > >//cpp.2 >#include > >int main() >{ >list my_list02; >return 0; >} > >------------------------------ > >If I compile these files using b19: > > g++ -c -frepo -fno-implicit-templates 1.cpp 2.cpp > g++ -frepo 1.o 2.o > >the compile fails. This happens in the same way regardless of the >behavior of freopen. > >Also I just noticed that my g++ et al aren't being installed correctly >because they aren't getting a .exe suffix appended during build time. >I'll have to fix the makefiles... That's too bad. I guess I should have known it wouldn't be that easy. I checked out the "Single UNIX" specification for freopen today and it seems that the newlib freopen is not exactly "up to spec". According to the man page, freopen *always* closes its stream argument first before attempting to open the new file. The newlib freopen seems to go to some effort to ensure that the stream argument is not closed until the filename has been opened. If you remove my patch and just make the freopen close the file prior to opening the new file, freopen may act more like UNIX. I don't see why that would fix the collect2 problem, but I think you'll get a similar effect to my patch -- at least if you're careful when opening stdin/stdout/stderr. -- http://www.bbc.com/ cgf AT bbc DOT com "Strange how unreal VMS=>UNIX Solutions Boston Business Computing the real can be."