This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: FreeBSD Fortran Failure
- To: gcc-bugs at gcc dot gnu dot org
- Subject: Re: FreeBSD Fortran Failure
- From: Loren James Rittle <rittle at latour dot rsch dot comm dot mot dot com>
- Date: Mon, 14 May 2001 21:05:39 -0500 (CDT)
- Cc: moene at knmi dot nl
- Organization: Networks and Infrastructure Lab (IL02/2240), Motorola Labs
In article <3AFF7F92.40BE15B3@knmi.nl> you write:
>Mark wrote:
>
>> Anyhow, immediately upon return to our caller (f_rew), we call
>> `rewind', which is supposed to be exactly equivalent to an
>> appropriate `fseek'.
>
>> It is possible that this a bug in OpenBSD.
> ^^^^ Free
>
>> In which case, we need to do the freopen thing anyhow.
>
>Yep, I agree with this analysis (even the last sentence ;-)
>
>I'll cook up a patch tonight for you to test.
>
>Thanks for the analysis.
I have to completely disagree with all of the analysis I have seen to
this point. ;-)
Here is my statement and analysis of the problem.
The problem is that no prototype for ftruncate() is seen in scope
while the code in libf2c/libI77/endfile.c is compiled. I found this
by noticing that the truncated size of the temporary file in the test
case was a seemingly random large number of bytes instead of 6 (and
then 3) bytes like it should have been.
After looking at the output of ``truss io1.x'' and using gdb, I
immediately wondered if the correct prototype was been seen (off_t is
a 64-bit size on FreeBSD and standard convention would pass the second
argument as a 32-bit int on this platform with no prototype):
int ftruncate __P((int, off_t));
Unfortunately, this prototype is only available on FreeBSD 4.2 (and
later, I assume) when you include unistd.h (or other headers) *without*
_POSIX_SOURCE defined!
To confirm the problem, I added -Wall to CFLAGS in the correct
makefile and forced a rebuild of libf2c/libI77/endfile.c:
/usr/users/rittle/tmp/gcc-build-latour-mainline-0511/gcc/xgcc -B/usr/users/rittle/tmp/gcc-build-latour-mainline-0511/gcc/ -B/usr/local/beta-gcc/i386-unknown-freebsd4.2/bin/ -B/usr/local/beta-gcc/i386-unknown-freebsd4.2/lib/ -isystem /usr/local/beta-gcc/i386-unknown-freebsd4.2/include -c -DSkip_f2c_Undefs -DAllow_TYQUAD -I. -I/usr/users/rittle/outside-cvs-src/gcc-mainline/libf2c/libI77 -I.. -I/usr/users/rittle/outside-cvs-src/gcc-mainline/libf2c/libI77/.. -DSTDC_HEADERS=1 -D_POSIX_SOURCE=1 -DHAVE_FTRUNCATE=1 -DHAVE_MKSTEMP=1 -DHAVE_TEMPNAM=1 -DNON_ANSI_RW_MODES=1 -DNO_EOF_CHAR_CHECK=1 -DSkip_f2c_Undefs=1 -g -O2 -Wall /usr/users/rittle/outside-cvs-src/gcc-mainline/libf2c/libI77/endfile.c
/usr/users/rittle/outside-cvs-src/gcc-mainline/libf2c/libI77/endfile.c: In function `f_end':
/usr/users/rittle/outside-cvs-src/gcc-mainline/libf2c/libI77/endfile.c:35: warning: suggest parentheses around assignment used as truth value
/usr/users/rittle/outside-cvs-src/gcc-mainline/libf2c/libI77/endfile.c: In function `t_runc':
/usr/users/rittle/outside-cvs-src/gcc-mainline/libf2c/libI77/endfile.c:132: warning: int format, long int arg (arg 3)
/usr/users/rittle/outside-cvs-src/gcc-mainline/libf2c/libI77/endfile.c:133: warning: implicit declaration of function `ftruncate'
S rittle@latour; pwd
/usr/users/rittle/tmp/gcc-build-latour-mainline-0511/i386-unknown-freebsd4.2/libf2c/libI77
If I change endfile.c so that it gets the correct prototype for
ftruncate(), the io1 test case passes like a fine Swiss watch.
Here is the lame patch I used to ensure that once we get the valid
prototype, everything works as expected:
S rittle@latour; ccvs diff -c endfile.c
Index: endfile.c
===================================================================
RCS file: /cvs/gcc/egcs/libf2c/libI77/endfile.c,v
retrieving revision 1.5
diff -c -r1.5 endfile.c
*** endfile.c 2001/02/26 20:23:41 1.5
--- endfile.c 2001/05/15 01:42:39
***************
*** 1,7 ****
--- 1,9 ----
#include "f2c.h"
#include "fio.h"
+ #undef _POSIX_SOURCE
#include <unistd.h>
+ #define _POSIX_SOURCE 1
#ifdef KR_headers
extern char *strcpy();
If you find it odd that FreeBSD only exposes ftruncate when
_POSIX_SOURCE is *not* defined, then join the club. My only guess is
that BSD added it in BSD 4.2 which (maybe) was some time before POSIX
added it...
Regards,
Loren