iostat
Steve Kargl
sgk@troutmask.apl.washington.edu
Wed Aug 23 18:38:00 GMT 2006
On Wed, Aug 23, 2006 at 07:53:10PM +0200, Daniel Franke wrote:
> > void
> > iostat_to_msg(GFC_INTEGER_4 *iostat, char *msg, gfc_charlen_type len)
> > {
> > strncpy(msg, strerror(*iostat), len-1);
> > }
>
> Isn't this what the perror() extension is about?
> It does not take iostat as argument, but works nevertheless ...
>
libc perror() finds the error message corresponding to the
current value of the global variable errno. It may have
changed for example by any cleanup in gfortran's open()
that may occur after a failed libc open(2).
str = 'Main: '
open(unit=1, file='yada', iostat=i1)
if (i1 /= 0) then
call perror(str) ! Does errno correspond to i1?
end if
Additionally, the libc perror() writes to stderr. For
whatever reason, a user may want to query for an error string
and take evasive action
if (i1 /= 0) then
call iostat_to_msg(i1, msg)
if (index(msg, 'not found') /= 0) then
! Do something about a missing file.
else if (index(msg, 'permission') /= 0) then
! Change the permission if possible
call chmod(...) ! Nonportable
else
...
end if
end if
--
Steve
More information about the Fortran
mailing list