This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[gfortran] patch for pr 18983 - can't write to /dev/null


here is the code that wasn't working:

       open(10,file="/dev/null")
       write(10,*) "Hello, world"
       end

we were calling ftruncate on this file. which gave an error.

added a check to only truncate the file when the file 
is bigger than the current record (like when we have just 
rewound a sequential file and have written a record).


No additional testsuite failures on i686/linux FC2.
No change to the NIST testsuite.

the "style police" may request that the code collapses into
(....  &&  ...) instead of the nested if's; no problem :):)


--bud



2004-12-30  Bud Davis  <bdavis9659@comcast.net>
	
	PR fortran/18983
	* io/transfer.c (st_write_done): only truncate when it
	is required.

Index: gcc/libgfortran/io/transfer.c
===================================================================
RCS file: /cvs/gcc/gcc/libgfortran/io/transfer.c,v
retrieving revision 1.23
diff -c -3 -p -r1.23 transfer.c
*** gcc/libgfortran/io/transfer.c	24 Dec 2004 00:29:07 -0000	1.23
--- gcc/libgfortran/io/transfer.c	29 Dec 2004 09:44:19 -0000
*************** st_write_done (void)
*** 1547,1555 ****
  	current_unit->endfile = AT_ENDFILE;	/* Just at it now.  */
  	break;
  
!       case NO_ENDFILE:	/* Get rid of whatever is after this record.  */
! 	if (struncate (current_unit->s) == FAILURE)
! 	  generate_error (ERROR_OS, NULL);
  
  	current_unit->endfile = AT_ENDFILE;
  	break;
--- 1547,1559 ----
  	current_unit->endfile = AT_ENDFILE;	/* Just at it now.  */
  	break;
  
!       case NO_ENDFILE:
! 	if (current_unit->current_record > current_unit->last_record)
!           {
!             /* Get rid of whatever is after this record.  */
!             if (struncate (current_unit->s) == FAILURE)
!               generate_error (ERROR_OS, NULL);
!           }
  
  	current_unit->endfile = AT_ENDFILE;
  	break;






! pr18983
! could not write to /dev/null
       integer i
       open(10,file="/dev/null")
       do i = 1,100
         write(10,*) "Hello, world"
       end do
       end





Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]