iostat

Steve Kargl sgk@troutmask.apl.washington.edu
Wed Aug 23 20:56:00 GMT 2006


On Wed, Aug 23, 2006 at 01:16:17PM -0700, Richard E Maine wrote:
> On Aug 23, 2006, at 12:33 PM, Steve Kargl wrote:
> 
> >I'm not opposed to giving information to a user.  I simply think
> >that returning a vague iostat=errno value is only marginally better
> >than the all inclusive 1 that is returned at the moment.
> 
> I guess we just do disagree, then because to me the difference is  
> huge - it is the difference between having zero information versus  
> having some.
> 
> I have personally had to deal with users asking why an OPEN failed.  
> In fact, I've had to deal with it quite a lot. That's why the subject  
> is of such interest to me. I'm not specking of abstract concerns, but  
> of situations I have actually been in many times. I've been the one  
> they asked for interpretation of the mysterious iostat number.
> 

Fine.  I give.  Uncle.  :-)

Here's a patch that returns errno for OS related errors.  The
following program 

program z
   ! aaa is owned by root.
   open(unit=1, file='aaa', status='old', iostat=ios)
   if (ios /= 0 ) then
      print *, ios
   end if

   ! ggg does not exit.
   open(unit=1, file='ggg', status='old', iostat=ios)
   if (ios /= 0 ) then
      print *, ios
   end if
end program z

gives

% ./a.out
       13
        2


2006-08-23  Steven G. Kargl  <kargls@comcast.net>

	* runtime/error.c: Return errno for iostat on OS errors.


Index: error.c
===================================================================
--- error.c	(revision 116323)
+++ error.c	(working copy)
@@ -34,6 +34,7 @@
 #include <stdarg.h>
 #include <string.h>
 #include <float.h>
+#include <errno.h>
 
 #include "libgfortran.h"
 #include "../io/io.h"
@@ -457,7 +458,7 @@
 {
   /* Set the error status.  */
   if ((cmp->flags & IOPARM_HAS_IOSTAT))
-    *cmp->iostat = family;
+    *cmp->iostat = (family == ERROR_OS) ? errno : family;
 
   if (message == NULL)
     message =
-- 
Steve



More information about the Fortran mailing list