diff options
author | Janne Blomqvist <jb@gcc.gnu.org> | 2011-10-31 16:52:26 +0200 |
---|---|---|
committer | Janne Blomqvist <jb@gcc.gnu.org> | 2011-10-31 16:52:26 +0200 |
commit | 3469bd8660b6c79a4727287ef4214d2b9c864ba6 (patch) | |
tree | 9abe59faaeca5c3b0989af7c8a5b04030589fb90 /libgfortran/io/unix.c | |
parent | 7d5ee219357f0ec4e9d67285eec50677ff2583ce (diff) | |
download | gcc-3469bd8660b6c79a4727287ef4214d2b9c864ba6.zip gcc-3469bd8660b6c79a4727287ef4214d2b9c864ba6.tar.gz gcc-3469bd8660b6c79a4727287ef4214d2b9c864ba6.tar.bz2 |
Introduce a size member function to struct stream.
2011-10-31 Janne Blomqvist <jb@gcc.gnu.org>
* io/unix.h (struct stream): Add size function pointer.
(ssize): New inline function.
(file_length): Remove prototype.
* io/unix.c (raw_size): New function.
(raw_init): Initialize st.size pointer.
(buf_size): New function.
(buf_init): Initialize st.size pointer.
(open_internal): Likewise.
(open_internal4): Likewise.
(file_length): Remove function.
* io/file_pos.c (st_rewind): Use ssize instead of file_length.
* io/open.c (test_endfile): Likewise.
* io/transfer.c (data_transfer_init): Likewise.
(next_record_r): Likewise.
(next_record_w): Likewise.
* io/unit.c (update_position): Likewise.
From-SVN: r180702
Diffstat (limited to 'libgfortran/io/unix.c')
-rw-r--r-- | libgfortran/io/unix.c | 39 |
1 files changed, 24 insertions, 15 deletions
diff --git a/libgfortran/io/unix.c b/libgfortran/io/unix.c index 00f7c72..c87be13 100644 --- a/libgfortran/io/unix.c +++ b/libgfortran/io/unix.c @@ -332,6 +332,16 @@ raw_tell (unix_stream * s) return lseek (s->fd, 0, SEEK_CUR); } +static gfc_offset +raw_size (unix_stream * s) +{ + struct stat statbuf; + int ret = fstat (s->fd, &statbuf); + if (ret == -1) + return ret; + return statbuf.st_size; +} + static int raw_truncate (unix_stream * s, gfc_offset length) { @@ -398,6 +408,7 @@ raw_init (unix_stream * s) s->st.write = (void *) raw_write; s->st.seek = (void *) raw_seek; s->st.tell = (void *) raw_tell; + s->st.size = (void *) raw_size; s->st.trunc = (void *) raw_truncate; s->st.close = (void *) raw_close; s->st.flush = (void *) raw_flush; @@ -584,6 +595,12 @@ buf_tell (unix_stream * s) return buf_seek (s, 0, SEEK_CUR); } +static gfc_offset +buf_size (unix_stream * s) +{ + return s->file_length; +} + static int buf_truncate (unix_stream * s, gfc_offset length) { @@ -613,6 +630,7 @@ buf_init (unix_stream * s) s->st.write = (void *) buf_write; s->st.seek = (void *) buf_seek; s->st.tell = (void *) buf_tell; + s->st.size = (void *) buf_size; s->st.trunc = (void *) buf_truncate; s->st.close = (void *) buf_close; s->st.flush = (void *) buf_flush; @@ -884,6 +902,9 @@ open_internal (char *base, int length, gfc_offset offset) s->st.close = (void *) mem_close; s->st.seek = (void *) mem_seek; s->st.tell = (void *) mem_tell; + /* buf_size is not a typo, we just reuse an identical + implementation. */ + s->st.size = (void *) buf_size; s->st.trunc = (void *) mem_truncate; s->st.read = (void *) mem_read; s->st.write = (void *) mem_write; @@ -912,6 +933,9 @@ open_internal4 (char *base, int length, gfc_offset offset) s->st.close = (void *) mem_close; s->st.seek = (void *) mem_seek; s->st.tell = (void *) mem_tell; + /* buf_size is not a typo, we just reuse an identical + implementation. */ + s->st.size = (void *) buf_size; s->st.trunc = (void *) mem_truncate; s->st.read = (void *) mem_read4; s->st.write = (void *) mem_write4; @@ -1740,21 +1764,6 @@ inquire_readwrite (const char *string, int len) } -/* file_length()-- Return the file length in bytes, -1 if unknown */ - -gfc_offset -file_length (stream * s) -{ - gfc_offset curr, end; - curr = stell (s); - if (curr == -1) - return curr; - end = sseek (s, 0, SEEK_END); - sseek (s, curr, SEEK_SET); - return end; -} - - int stream_isatty (stream *s) { |