diff options
author | Jerry DeLisle <jvdelisle@gcc.gnu.org> | 2009-09-13 03:41:41 +0000 |
---|---|---|
committer | Jerry DeLisle <jvdelisle@gcc.gnu.org> | 2009-09-13 03:41:41 +0000 |
commit | ee3eb6a416c996acf33fca5ecb5cd281b2c70c09 (patch) | |
tree | c6c335c0e6e5abcfe1decf752fb951e29ab32235 | |
parent | efcc709b4fe72f8b5c4415b31e542a089599bd1d (diff) | |
download | gcc-ee3eb6a416c996acf33fca5ecb5cd281b2c70c09.zip gcc-ee3eb6a416c996acf33fca5ecb5cd281b2c70c09.tar.gz gcc-ee3eb6a416c996acf33fca5ecb5cd281b2c70c09.tar.bz2 |
re PR fortran/41328 (bad iostat when reading DOS file in a character array (non-advancing))
2009-09-12 Jerry DeLisle <jvdelisle@gcc.gnu.org>
PR libgfortran/41328
* io/transfer.c (read_sf): Adjust fbuf position and do proper
fbuf reads to traverse CR, CR-LF, and LF style line ends.
From-SVN: r151665
-rw-r--r-- | libgfortran/ChangeLog | 6 | ||||
-rw-r--r-- | libgfortran/io/transfer.c | 25 |
2 files changed, 21 insertions, 10 deletions
diff --git a/libgfortran/ChangeLog b/libgfortran/ChangeLog index 1b2e961..3469814 100644 --- a/libgfortran/ChangeLog +++ b/libgfortran/ChangeLog @@ -1,5 +1,11 @@ 2009-09-12 Jerry DeLisle <jvdelisle@gcc.gnu.org> + PR libgfortran/41328 + * io/transfer.c (read_sf): Adjust fbuf position and do proper + fbuf reads to traverse CR, CR-LF, and LF style line ends. + +2009-09-12 Jerry DeLisle <jvdelisle@gcc.gnu.org> + PR libgfortran/41219 * io/write.c (write_a_char4): Use correct type for crlf constant. diff --git a/libgfortran/io/transfer.c b/libgfortran/io/transfer.c index 59f88d4..2362a15 100644 --- a/libgfortran/io/transfer.c +++ b/libgfortran/io/transfer.c @@ -232,21 +232,28 @@ read_sf (st_parameter_dt *dtp, int * length, int no_error) if (q == '\n' || q == '\r') { - /* Unexpected end of line. */ + /* Unexpected end of line. Set the position. */ + fbuf_seek (dtp->u.p.current_unit, n + 1 ,SEEK_CUR); + dtp->u.p.sf_seen_eor = 1; /* If we see an EOR during non-advancing I/O, we need to skip the rest of the I/O statement. Set the corresponding flag. */ if (dtp->u.p.advance_status == ADVANCE_NO || dtp->u.p.seen_dollar) dtp->u.p.eor_condition = 1; - + /* If we encounter a CR, it might be a CRLF. */ if (q == '\r') /* Probably a CRLF */ { - if (n < *length && *(p + 1) == '\n') - dtp->u.p.sf_seen_eor = 2; + /* See if there is an LF. Use fbuf_read rather then fbuf_getc so + the position is not advanced unless it really is an LF. */ + int readlen = 1; + p = fbuf_read (dtp->u.p.current_unit, &readlen); + if (*p == '\n' && readlen == 1) + { + dtp->u.p.sf_seen_eor = 2; + fbuf_seek (dtp->u.p.current_unit, 1 ,SEEK_CUR); + } } - else - dtp->u.p.sf_seen_eor = 1; /* Without padding, terminate the I/O statement without assigning the value. With padding, the value still needs to be assigned, @@ -260,7 +267,7 @@ read_sf (st_parameter_dt *dtp, int * length, int no_error) } *length = n; - break; + goto done; } /* Short circuit the read if a comma is found during numeric input. The flag is set to zero during character reads so that commas in @@ -274,13 +281,11 @@ read_sf (st_parameter_dt *dtp, int * length, int no_error) *length = n; break; } - n++; p++; } - fbuf_seek (dtp->u.p.current_unit, n + dtp->u.p.sf_seen_eor + seen_comma, - SEEK_CUR); + fbuf_seek (dtp->u.p.current_unit, n + seen_comma, SEEK_CUR); /* A short read implies we hit EOF, unless we hit EOR, a comma, or some other stuff. Set the relevant flags. */ |