From e1c74af03afbd2cc8de5b4777e8f40cab6eab4bf Mon Sep 17 00:00:00 2001 From: Bud Davis Date: Sat, 15 Jan 2005 08:10:23 +0000 Subject: [PATCH] re PR libfortran/18983 (can't open /dev/null as an output file) 2005-01-15 Bud Davis PR fortran/18983 * io/transfer.c (st_write_done): only truncate when it is required. 2005-01-15 Bud Davis PR fortran/18983 * gfortran.dg/write_to_null.f90: New test. From-SVN: r93689 --- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gfortran.dg/write_to_null.f90 | 9 +++++++++ libgfortran/ChangeLog | 6 ++++++ libgfortran/io/transfer.c | 10 +++++++--- 4 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/gfortran.dg/write_to_null.f90 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index f0e7317b94ff..ba010eb95874 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2005-01-15 Bud Davis + + PR fortran/18983 + * gfortran.dg/write_to_null.f90: New test. + 2005-01-14 Andrew Pinski John David Anglin diff --git a/gcc/testsuite/gfortran.dg/write_to_null.f90 b/gcc/testsuite/gfortran.dg/write_to_null.f90 new file mode 100644 index 000000000000..c6f12cb2ec53 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/write_to_null.f90 @@ -0,0 +1,9 @@ +! { dg-do run } +! 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 diff --git a/libgfortran/ChangeLog b/libgfortran/ChangeLog index 6c2b12eaa6c9..c0534b8ef442 100644 --- a/libgfortran/ChangeLog +++ b/libgfortran/ChangeLog @@ -1,3 +1,9 @@ +2005-01-15 Bud Davis + + PR fortran/18983 + * io/transfer.c (st_write_done): only truncate when it + is required. + 2005-01-12 Toon Moene PR libfortran/19280 diff --git a/libgfortran/io/transfer.c b/libgfortran/io/transfer.c index 73b0b9aba5fb..545440790731 100644 --- a/libgfortran/io/transfer.c +++ b/libgfortran/io/transfer.c @@ -1557,9 +1557,13 @@ st_write_done (void) 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); + 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; -- 2.43.5