+2010-04-01 Janne Blomqvist <jb@gcc.gnu.org>
+ Manfred Schwarb <manfred99@gmx.ch>
+
+ PR libfortran/43605
+ * gfortran.dg/ftell_3.f90: New test.
+
2010-04-01 Richard Guenther <rguenther@suse.de>
PR middle-end/43614
! { dg-do run }
! PR43605 FTELL intrinsic returns incorrect position
-! Contributed by Janne Blomqvist, Manfred Schwarb
-! and Dominique d'Humieres.
+! Contributed by Janne Blomqvist and Manfred Schwarb
program ftell_3
integer :: i
character(len=99) :: buffer
if(i /= 7) then
call abort()
end if
- read(10,'(a)') buffer
- if (trim(buffer) /= "789") then
- call abort()
- end if
- call ftell(10,i)
- if (i /= 11) then
- call abort()
- end if
close(10)
end program ftell_3
+2010-04-01 Janne Blomqvist <jb@gcc.gnu.org>
+
+ PR libfortran/43605
+ * io/intrinsics.c (ftell): Reset fbuf, correct offset.
+ (FTELL_SUB): Likewise.
+
2010-03-29 Jerry DeLisle <jvdelisle@gcc.gnu.org>
PR libfortran/43265
/* FTELL intrinsic */
-static gfc_offset
-gf_ftell (int unit)
-{
- gfc_unit * u = find_unit (unit);
- if (u == NULL)
- return -1;
- int pos = fbuf_reset (u);
- if (pos != 0)
- sseek (u->s, pos, SEEK_CUR);
- gfc_offset ret = stell (u->s);
- unlock_unit (u);
- return ret;
-}
-
extern size_t PREFIX(ftell) (int *);
export_proto_np(PREFIX(ftell));
size_t
PREFIX(ftell) (int * unit)
{
- return gf_ftell (*unit);
+ gfc_unit * u = find_unit (*unit);
+ gfc_offset ret;
+ if (u == NULL)
+ return ((size_t) -1);
+ ret = stell (u->s) + fbuf_reset (u);
+ unlock_unit (u);
+ return ret;
}
#define FTELL_SUB(kind) \
void \
ftell_i ## kind ## _sub (int * unit, GFC_INTEGER_ ## kind * offset) \
{ \
- *offset = gf_ftell (*unit); \
+ gfc_unit * u = find_unit (*unit); \
+ if (u == NULL) \
+ *offset = -1; \
+ else \
+ { \
+ *offset = stell (u->s) + fbuf_reset (u); \
+ unlock_unit (u); \
+ } \
}
FTELL_SUB(1)