+2014-06-08 Janne Blomqvist <jb@gcc.gnu.org>
+
+ PR libfortran/56981
+ * io/unix.h (struct stream_vtable): Add new member function,
+ markeor.
+ (smarkeor): New inline function.
+ (flush_if_unbuffered): Remove prototype.
+ * io/unix.c (raw_markeor): New function.
+ (raw_vtable): Initialize markeor member.
+ (buf_markeor): New function.
+ (buf_vtable): Initialize markeor member.
+ (mem_vtable): Likewise.
+ (mem4_vtable): Likewise.
+ (flush_if_unbuffered): Remove function.
+ * io/transfer.c (next_record): Call smarkeor instead of
+ flush_if_unbuffered.
+
2014-05-27 Uros Bizjak <ubizjak@gmail.com>
* intrinsics/getcwd.c: Include stdlib.h.
return retval;
}
+static int
+raw_markeor (unix_stream * s __attribute__ ((unused)))
+{
+ return 0;
+}
+
static const struct stream_vtable raw_vtable = {
.read = (void *) raw_read,
.write = (void *) raw_write,
.size = (void *) raw_size,
.trunc = (void *) raw_truncate,
.close = (void *) raw_close,
- .flush = (void *) raw_flush
+ .flush = (void *) raw_flush,
+ .markeor = (void *) raw_markeor
};
static int
return nbyte;
}
+
+/* "Unbuffered" really means I/O statement buffering. For formatted
+ I/O, the fbuf manages this, and then uses raw I/O. For unformatted
+ I/O, buffered I/O is used, and the buffer is flushed at the end of
+ each I/O statement, where this function is called. Alternatively,
+ the buffer is flushed at the end of the record if the buffer is
+ more than half full; this prevents needless seeking back and forth
+ when writing sequential unformatted. */
+
+static int
+buf_markeor (unix_stream * s)
+{
+ if (s->unbuffered || s->ndirty >= BUFFER_SIZE / 2)
+ return buf_flush (s);
+ return 0;
+}
+
static gfc_offset
buf_seek (unix_stream * s, gfc_offset offset, int whence)
{
.size = (void *) buf_size,
.trunc = (void *) buf_truncate,
.close = (void *) buf_close,
- .flush = (void *) buf_flush
+ .flush = (void *) buf_flush,
+ .markeor = (void *) buf_markeor
};
static int
.size = (void *) buf_size,
.trunc = (void *) mem_truncate,
.close = (void *) mem_close,
- .flush = (void *) mem_flush
+ .flush = (void *) mem_flush,
+ .markeor = (void *) raw_markeor
};
static const struct stream_vtable mem4_vtable = {
.size = (void *) buf_size,
.trunc = (void *) mem_truncate,
.close = (void *) mem_close,
- .flush = (void *) mem_flush
+ .flush = (void *) mem_flush,
+ .markeor = (void *) raw_markeor
};
/*********************************************************************
}
-/* "Unbuffered" really means I/O statement buffering. For formatted
- I/O, the fbuf manages this, and then uses raw I/O. For unformatted
- I/O, buffered I/O is used, and the buffer is flushed at the end of
- each I/O statement, where this function is called. */
-
-int
-flush_if_unbuffered (stream* s)
-{
- unix_stream* us = (unix_stream*) s;
- if (us->unbuffered)
- return sflush (s);
- return 0;
-}
-
-
/* fd_to_stream()-- Given an open file descriptor, build a stream
* around it. */
int (* const trunc) (struct stream *, gfc_offset);
int (* const flush) (struct stream *);
int (* const close) (struct stream *);
+ int (* const markeor) (struct stream *);
};
struct stream
return s->vptr->close (s);
}
+static inline int
+smarkeor (stream * s)
+{
+ return s->vptr->markeor (s);
+}
+
extern int compare_files (stream *, stream *);
internal_proto(compare_files);
extern void flush_if_preconnected (stream *);
internal_proto(flush_if_preconnected);
-extern int flush_if_unbuffered (stream*);
-internal_proto(flush_if_unbuffered);
-
extern int stream_isatty (stream *);
internal_proto(stream_isatty);