+2006-09-14 Jerry DeLisle <jvdelisle@gcc.gnu.org>
+
+ PR libgfortran/29053
+ * io.h (gfc_unit): Add variable, strm_pos, to track
+ STREAM I/O file position.
+ * file_pos.c (st_rewind): Set strm_pos to beginning.
+ * open.c (new_unit): Initialize strm_pos.
+ * read.c (read_x): Bump strm_pos.
+ * inquire.c (inquire_via_unit): Return strm_pos value.
+ * transfer.c (read_block),(read_block_direct),(write_block)
+ (write_buf): Seek to strm_pos - 1. Update strm_pos when done.
+ (pre_position): Initialize strm_pos.
+ (data_transfer_init): Set strm_pos if DT_HAS_REC.
+ (finalize_transfer): Flush file, no need to update strm_pos.
+
2006-09-10 Paul Thomas <pault@gcc.gnu.org>
PR libfortran/28947
/* recl -- Record length of the file.
last_record -- Last record number read or written
maxrec -- Maximum record number in a direct access file
- bytes_left -- Bytes left in current record. */
- gfc_offset recl, last_record, maxrec, bytes_left;
+ bytes_left -- Bytes left in current record.
+ strm_pos -- Current position in file for STREAM I/O. */
+ gfc_offset recl, last_record, maxrec, bytes_left, strm_pos;
__gthread_mutex_t lock;
/* Number of threads waiting to acquire this unit's lock.
else
{
if (sseek (dtp->u.p.current_unit->s,
- (gfc_offset) (dtp->rec - 1)) == FAILURE)
+ dtp->u.p.current_unit->strm_pos - 1) == FAILURE)
{
generate_error (&dtp->common, ERROR_END, NULL);
return NULL;
}
}
- dtp->rec += (GFC_IO_INT) nread;
+ dtp->u.p.current_unit->strm_pos += (gfc_offset) nread;
}
return source;
}
else
{
if (sseek (dtp->u.p.current_unit->s,
- (gfc_offset) (dtp->rec - 1)) == FAILURE)
+ dtp->u.p.current_unit->strm_pos - 1) == FAILURE)
{
generate_error (&dtp->common, ERROR_END, NULL);
return;
dtp->u.p.size_used += (gfc_offset) nread;
}
else
- dtp->rec += (GFC_IO_INT) nread;
+ dtp->u.p.current_unit->strm_pos += (gfc_offset) nread;
if (nread != *nbytes) /* Short read, e.g. if we hit EOF. */
{
else
{
if (sseek (dtp->u.p.current_unit->s,
- (gfc_offset) (dtp->rec - 1)) == FAILURE)
+ dtp->u.p.current_unit->strm_pos - 1) == FAILURE)
{
- generate_error (&dtp->common, ERROR_END, NULL);
+ generate_error (&dtp->common, ERROR_OS, NULL);
return NULL;
}
return NULL;
}
- dtp->rec += (GFC_IO_INT) length;
+ dtp->u.p.current_unit->strm_pos += (gfc_offset) length;
}
return dest;
else
{
if (sseek (dtp->u.p.current_unit->s,
- (gfc_offset) (dtp->rec - 1)) == FAILURE)
+ dtp->u.p.current_unit->strm_pos - 1) == FAILURE)
{
generate_error (&dtp->common, ERROR_OS, NULL);
return FAILURE;
dtp->u.p.size_used += (gfc_offset) nbytes;
}
else
- dtp->rec += (GFC_IO_INT) nbytes;
+ dtp->u.p.current_unit->strm_pos += (gfc_offset) nbytes;
return SUCCESS;
}
/* There are no records with stream I/O. Set the default position
to the beginning of the file if no position was specified. */
if ((dtp->common.flags & IOPARM_DT_HAS_REC) == 0)
- dtp->rec = 1;
+ dtp->u.p.current_unit->strm_pos = 1;
break;
case UNFORMATTED_SEQUENTIAL:
}
/* Position the file. */
- if (sseek (dtp->u.p.current_unit->s, (gfc_offset) (dtp->rec - 1)
- * dtp->u.p.current_unit->recl) == FAILURE)
+ if (!is_stream_io (dtp))
{
- generate_error (&dtp->common, ERROR_OS, NULL);
- return;
+ if (sseek (dtp->u.p.current_unit->s, (gfc_offset) (dtp->rec - 1)
+ * dtp->u.p.current_unit->recl) == FAILURE)
+ {
+ generate_error (&dtp->common, ERROR_OS, NULL);
+ return;
+ }
}
+ else
+ dtp->u.p.current_unit->strm_pos = dtp->rec;
+
}
/* Overwriting an existing sequential file ?
next_record (dtp, 1);
}
else
- {
- flush (dtp->u.p.current_unit->s);
- dtp->u.p.current_unit->last_record = dtp->rec;
- }
+ flush (dtp->u.p.current_unit->s);
sfree (dtp->u.p.current_unit->s);
}