re PR fortran/31366 ([4.2 only] Last record truncated for read after short write...
authorJerry DeLisle <jvdelisle@gcc.gnu.org>
Sun, 1 Apr 2007 15:23:48 +0000 (15:23 +0000)
committerJerry DeLisle <jvdelisle@gcc.gnu.org>
Sun, 1 Apr 2007 15:23:48 +0000 (15:23 +0000)
2007-04-01  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

PR libgfortran/31366
* io/transfer.c (read_block_direct): Do not generate error when reading
past EOF on a short record that is less than the RECL= specified.

2007-04-01  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

PR libgfortran/31207
* io/unit.c (close_unit_1): If there are bytes previously written from
ADVANCE="no", move to the end before closing.

From-SVN: r123401

libgfortran/ChangeLog
libgfortran/io/transfer.c
libgfortran/io/unit.c

index 6b8f4f8..761e5b9 100644 (file)
@@ -1,3 +1,15 @@
+2007-04-01  Jerry DeLisle  <jvdelisle@gcc.gnu.org>
+
+       PR libgfortran/31366
+       * io/transfer.c (read_block_direct): Do not generate error when reading
+       past EOF on a short record that is less than the RECL= specified.
+       
+2007-04-01  Jerry DeLisle  <jvdelisle@gcc.gnu.org>
+
+       PR libgfortran/31207
+       * io/unit.c (close_unit_1): If there are bytes previously written from
+       ADVANCE="no", move to the end before closing.
+
 2007-03-31  Francois-Xavier Coudert  <fxcoudert@gcc.gnu.org>
 
        PR libfortran/31335
index 2555898..3c6deb4 100644 (file)
@@ -411,7 +411,6 @@ read_block_direct (st_parameter_dt *dtp, void *buf, size_t *nbytes)
          /* Short read, e.g. if we hit EOF.  Apparently, we read
           more than was written to the last record.  */
          *nbytes = to_read_record;
-         generate_error (&dtp->common, ERROR_SHORT_RECORD, NULL);
          return;
        }
 
index 90e6d85..2d2c742 100644 (file)
@@ -590,6 +590,30 @@ close_unit_1 (gfc_unit *u, int locked)
 {
   int i, rc;
 
+  /* If there are previously written bytes from a write with ADVANCE="no"
+     Reposition the buffer before closing.  */
+  if (u->saved_pos > 0)
+    {
+      char *p;
+
+      p = salloc_w (u->s, &u->saved_pos);
+
+      if (!(u->unit_number == options.stdout_unit
+           || u->unit_number == options.stderr_unit))
+       {
+         size_t len;
+
+         const char crlf[] = "\r\n";
+#ifdef HAVE_CRLF
+         len = 2;
+#else
+         len = 1;
+#endif
+         if (swrite (u->s, &crlf[2-len], &len) != 0)
+           os_error ("Close after ADVANCE_NO failed");
+       }
+    }
+
   rc = (u->s == NULL) ? 0 : sclose (u->s) == FAILURE;
 
   u->closed = 1;