PR 78534, 83704 Handle large formatted I/O
[gcc.git] / libgfortran / io / inquire.c
index 5e0cf3e646c3a5d1f75b848c2bd41e1aea82d63f..047be39ec7af0f26e47620288422ddb8054aefa8 100644 (file)
@@ -1,63 +1,56 @@
-/* Copyright (C) 2002, 2003, 2005, 2007 Free Software Foundation, Inc.
+/* Copyright (C) 2002-2018 Free Software Foundation, Inc.
    Contributed by Andy Vaught
 
-This file is part of the GNU Fortran 95 runtime library (libgfortran).
+This file is part of the GNU Fortran runtime library (libgfortran).
 
 Libgfortran is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2, or (at your option)
+the Free Software Foundation; either version 3, or (at your option)
 any later version.
 
-In addition to the permissions in the GNU General Public License, the
-Free Software Foundation gives you unlimited permission to link the
-compiled version of this file into combinations with other programs,
-and to distribute those combinations without any restriction coming
-from the use of this file.  (The General Public License restrictions
-do apply in other respects; for example, they cover modification of
-the file, and distribution when not linked into a combine
-executable.)
-
 Libgfortran is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 
-You should have received a copy of the GNU General Public License
-along with Libgfortran; see the file COPYING.  If not, write to
-the Free Software Foundation, 51 Franklin Street, Fifth Floor,
-Boston, MA 02110-1301, USA.  */
+Under Section 7 of GPL version 3, you are granted additional
+permissions described in the GCC Runtime Library Exception, version
+3.1, as published by the Free Software Foundation.
+
+You should have received a copy of the GNU General Public License and
+a copy of the GCC Runtime Library Exception along with this program;
+see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+<http://www.gnu.org/licenses/>.  */
 
 
 /* Implement the non-IOLENGTH variant of the INQUIRY statement */
 
 #include "io.h"
+#include "unix.h"
+#include <string.h>
 
 
-static const char undefined[] = "UNDEFINED";
+static const char yes[] = "YES", no[] = "NO", undefined[] = "UNDEFINED";
 
 
 /* inquire_via_unit()-- Inquiry via unit number.  The unit might not exist. */
 
 static void
-inquire_via_unit (st_parameter_inquire *iqp, gfc_unit * u)
+inquire_via_unit (st_parameter_inquire *iqp, gfc_unit *u)
 {
   const char *p;
   GFC_INTEGER_4 cf = iqp->common.flags;
-  GFC_INTEGER_4 cf2 = iqp->flags2;
 
-  if ((cf & IOPARM_INQUIRE_HAS_EXIST) != 0)
-    {
-      *iqp->exist = (iqp->common.unit >= 0
-                    && iqp->common.unit <= GFC_INTEGER_4_HUGE);
+  if (iqp->common.unit == GFC_INTERNAL_UNIT ||
+       iqp->common.unit == GFC_INTERNAL_UNIT4 ||
+       (u != NULL && u->internal_unit_kind != 0))
+    generate_error (&iqp->common, LIBERROR_INQUIRE_INTERNAL_UNIT, NULL);
 
-      if ((cf & IOPARM_INQUIRE_HAS_FILE) == 0)
-       {
-         if (!(*iqp->exist))
-           *iqp->common.iostat = LIBERROR_BAD_UNIT;
-         *iqp->exist = *iqp->exist
-                       && (*iqp->common.iostat != LIBERROR_BAD_UNIT);
-       }
-    }
+  if ((cf & IOPARM_INQUIRE_HAS_EXIST) != 0)
+    *iqp->exist = (u != NULL &&
+                  iqp->common.unit != GFC_INTERNAL_UNIT &&
+                  iqp->common.unit != GFC_INTERNAL_UNIT4)
+               || (iqp->common.unit >= 0);
 
   if ((cf & IOPARM_INQUIRE_HAS_OPENED) != 0)
     *iqp->opened = (u != NULL);
@@ -70,7 +63,37 @@ inquire_via_unit (st_parameter_inquire *iqp, gfc_unit * u)
 
   if ((cf & IOPARM_INQUIRE_HAS_NAME) != 0
       && u != NULL && u->flags.status != STATUS_SCRATCH)
-    fstrcpy (iqp->name, iqp->name_len, u->file, u->file_len);
+    {
+#if defined(HAVE_TTYNAME_R) || defined(HAVE_TTYNAME)
+      if (u->unit_number == options.stdin_unit
+         || u->unit_number == options.stdout_unit
+         || u->unit_number == options.stderr_unit)
+       {
+         int err = stream_ttyname (u->s, iqp->name, iqp->name_len);
+         if (err == 0)
+           {
+             gfc_charlen_type tmplen = strlen (iqp->name);
+             if (iqp->name_len > tmplen)
+               memset (&iqp->name[tmplen], ' ', iqp->name_len - tmplen);
+           }
+         else /* If ttyname does not work, go with the default.  */
+           cf_strcpy (iqp->name, iqp->name_len, u->filename);
+       }
+      else
+       cf_strcpy (iqp->name, iqp->name_len, u->filename);
+#elif defined __MINGW32__
+      if (u->unit_number == options.stdin_unit)
+       fstrcpy (iqp->name, iqp->name_len, "CONIN$", sizeof("CONIN$"));
+      else if (u->unit_number == options.stdout_unit)
+       fstrcpy (iqp->name, iqp->name_len, "CONOUT$", sizeof("CONOUT$"));
+      else if (u->unit_number == options.stderr_unit)
+       fstrcpy (iqp->name, iqp->name_len, "CONERR$", sizeof("CONERR$"));
+      else
+       cf_strcpy (iqp->name, iqp->name_len, u->filename);
+#else
+      cf_strcpy (iqp->name, iqp->name_len, u->filename);
+#endif
+    }
 
   if ((cf & IOPARM_INQUIRE_HAS_ACCESS) != 0)
     {
@@ -104,10 +127,10 @@ inquire_via_unit (st_parameter_inquire *iqp, gfc_unit * u)
          {
          case ACCESS_DIRECT:
          case ACCESS_STREAM:
-           p = "NO";
+           p = no;
            break;
          case ACCESS_SEQUENTIAL:
-           p = "YES";
+           p = yes;
            break;
          default:
            internal_error (&iqp->common, "inquire_via_unit(): Bad access");
@@ -125,10 +148,10 @@ inquire_via_unit (st_parameter_inquire *iqp, gfc_unit * u)
          {
          case ACCESS_SEQUENTIAL:
          case ACCESS_STREAM:
-           p = "NO";
+           p = no;
            break;
          case ACCESS_DIRECT:
-           p = "YES";
+           p = yes;
            break;
          default:
            internal_error (&iqp->common, "inquire_via_unit(): Bad access");
@@ -165,10 +188,10 @@ inquire_via_unit (st_parameter_inquire *iqp, gfc_unit * u)
        switch (u->flags.form)
          {
          case FORM_FORMATTED:
-           p = "YES";
+           p = yes;
            break;
          case FORM_UNFORMATTED:
-           p = "NO";
+           p = no;
            break;
          default:
            internal_error (&iqp->common, "inquire_via_unit(): Bad form");
@@ -185,10 +208,10 @@ inquire_via_unit (st_parameter_inquire *iqp, gfc_unit * u)
        switch (u->flags.form)
          {
          case FORM_FORMATTED:
-           p = "NO";
+           p = no;
            break;
          case FORM_UNFORMATTED:
-           p = "YES";
+           p = yes;
            break;
          default:
            internal_error (&iqp->common, "inquire_via_unit(): Bad form");
@@ -198,7 +221,9 @@ inquire_via_unit (st_parameter_inquire *iqp, gfc_unit * u)
     }
 
   if ((cf & IOPARM_INQUIRE_HAS_RECL_OUT) != 0)
-    *iqp->recl_out = (u != NULL) ? u->recl : 0;
+    /* F2018 (N2137) 12.10.2.26: If there is no connection, recl is
+       assigned the value -1.  */
+    *iqp->recl_out = (u != NULL) ? u->recl : -1;
 
   if ((cf & IOPARM_INQUIRE_HAS_STRM_POS_OUT) != 0)
     *iqp->strm_pos_out = (u != NULL) ? u->strm_pos : 0;
@@ -240,10 +265,10 @@ inquire_via_unit (st_parameter_inquire *iqp, gfc_unit * u)
        switch (u->flags.pad)
          {
          case PAD_YES:
-           p = "YES";
+           p = yes;
            break;
          case PAD_NO:
-           p = "NO";
+           p = no;
            break;
          default:
            internal_error (&iqp->common, "inquire_via_unit(): Bad pad");
@@ -252,126 +277,214 @@ inquire_via_unit (st_parameter_inquire *iqp, gfc_unit * u)
       cf_strcpy (iqp->pad, iqp->pad_len, p);
     }
 
-  if ((cf2 & IOPARM_INQUIRE_HAS_PENDING) != 0)
-    *iqp->pending = 0;
-  
-  if ((cf2 & IOPARM_INQUIRE_HAS_ID) != 0)
-    *iqp->id = 0;
-
-  if ((cf2 & IOPARM_INQUIRE_HAS_ENCODING) != 0)
+  if (cf & IOPARM_INQUIRE_HAS_FLAGS2)
     {
-      if (u == NULL || u->flags.form != FORM_FORMATTED)
-       p = undefined;
-      else
-       switch (u->flags.encoding)
-         {
-         case ENCODING_DEFAULT:
-           p = "UNKNOWN";
-           break;
-         /* TODO: Enable UTF-8 case here when implemented.
-         case ENCODING_UTF8:
-           p = "UTF-8";
-           break; */
-         default:
-           internal_error (&iqp->common, "inquire_via_unit(): Bad encoding");
-         }
+      GFC_INTEGER_4 cf2 = iqp->flags2;
 
-      cf_strcpy (iqp->encoding, iqp->encoding_len, p);
-    }
+      if ((cf2 & IOPARM_INQUIRE_HAS_PENDING) != 0)
+       *iqp->pending = 0;
+  
+      if ((cf2 & IOPARM_INQUIRE_HAS_ID) != 0)
+        *iqp->id = 0;
 
-  if ((cf2 & IOPARM_INQUIRE_HAS_DECIMAL) != 0)
-    {
-      if (u == NULL || u->flags.form != FORM_FORMATTED)
-       p = undefined;
-      else
-       switch (u->flags.decimal)
-         {
-         case DECIMAL_POINT:
-           p = "POINT";
-           break;
-         case DECIMAL_COMMA:
-           p = "COMMA";
-           break;
-         default:
-           internal_error (&iqp->common, "inquire_via_unit(): Bad comma");
-         }
+      if ((cf2 & IOPARM_INQUIRE_HAS_ENCODING) != 0)
+       {
+         if (u == NULL || u->flags.form != FORM_FORMATTED)
+           p = undefined;
+          else
+           switch (u->flags.encoding)
+             {
+             case ENCODING_DEFAULT:
+               p = "UNKNOWN";
+               break;
+             case ENCODING_UTF8:
+               p = "UTF-8";
+               break;
+             default:
+               internal_error (&iqp->common, "inquire_via_unit(): Bad encoding");
+             }
+
+         cf_strcpy (iqp->encoding, iqp->encoding_len, p);
+       }
 
-      cf_strcpy (iqp->decimal, iqp->decimal_len, p);
-    }
+      if ((cf2 & IOPARM_INQUIRE_HAS_DECIMAL) != 0)
+       {
+         if (u == NULL || u->flags.form != FORM_FORMATTED)
+           p = undefined;
+         else
+           switch (u->flags.decimal)
+             {
+             case DECIMAL_POINT:
+               p = "POINT";
+               break;
+             case DECIMAL_COMMA:
+               p = "COMMA";
+               break;
+             default:
+               internal_error (&iqp->common, "inquire_via_unit(): Bad comma");
+             }
+
+         cf_strcpy (iqp->decimal, iqp->decimal_len, p);
+       }
 
-  if ((cf2 & IOPARM_INQUIRE_HAS_ASYNCHRONOUS) != 0)
-    {
-      if (u == NULL)
-       p = undefined;
-      else
-       switch (u->flags.async)
-         {
-         case ASYNC_YES:
-           p = "YES";
-           break;
-         case ASYNC_NO:
-           p = "NO";
-           break;
-         default:
-           internal_error (&iqp->common, "inquire_via_unit(): Bad async");
-         }
+      if ((cf2 & IOPARM_INQUIRE_HAS_ASYNCHRONOUS) != 0)
+       {
+         if (u == NULL)
+           p = undefined;
+         else
+           switch (u->flags.async)
+           {
+             case ASYNC_YES:
+               p = yes;
+               break;
+             case ASYNC_NO:
+               p = no;
+               break;
+             default:
+               internal_error (&iqp->common, "inquire_via_unit(): Bad async");
+           }
+
+         cf_strcpy (iqp->asynchronous, iqp->asynchronous_len, p);
+       }
 
-      cf_strcpy (iqp->asynchronous, iqp->asynchronous_len, p);
-    }
+      if ((cf2 & IOPARM_INQUIRE_HAS_SIGN) != 0)
+       {
+         if (u == NULL)
+           p = undefined;
+         else
+           switch (u->flags.sign)
+           {
+             case SIGN_PROCDEFINED:
+               p = "PROCESSOR_DEFINED";
+               break;
+             case SIGN_SUPPRESS:
+               p = "SUPPRESS";
+               break;
+             case SIGN_PLUS:
+               p = "PLUS";
+               break;
+             default:
+               internal_error (&iqp->common, "inquire_via_unit(): Bad sign");
+           }
+
+         cf_strcpy (iqp->sign, iqp->sign_len, p);
+       }
 
-  if ((cf2 & IOPARM_INQUIRE_HAS_SIGN) != 0)
-    {
-      if (u == NULL)
-       p = undefined;
-      else
-       switch (u->flags.sign)
-         {
-         case SIGN_PROCDEFINED:
-           p = "PROCESSOR_DEFINED";
-           break;
-         case SIGN_SUPPRESS:
-           p = "SUPPRESS";
-           break;
-         case SIGN_PLUS:
-           p = "PLUS";
-           break;
-         default:
-           internal_error (&iqp->common, "inquire_via_unit(): Bad sign");
-         }
+      if ((cf2 & IOPARM_INQUIRE_HAS_ROUND) != 0)
+       {
+         if (u == NULL)
+           p = undefined;
+         else
+           switch (u->flags.round)
+           {
+             case ROUND_UP:
+               p = "UP";
+               break;
+             case ROUND_DOWN:
+               p = "DOWN";
+               break;
+             case ROUND_ZERO:
+               p = "ZERO";
+               break;
+             case ROUND_NEAREST:
+               p = "NEAREST";
+               break;
+             case ROUND_COMPATIBLE:
+               p = "COMPATIBLE";
+               break;
+             case ROUND_PROCDEFINED:
+               p = "PROCESSOR_DEFINED";
+               break;
+             default:
+               internal_error (&iqp->common, "inquire_via_unit(): Bad round");
+           }
+
+         cf_strcpy (iqp->round, iqp->round_len, p);
+       }
 
-      cf_strcpy (iqp->sign, iqp->sign_len, p);
-    }
+      if ((cf2 & IOPARM_INQUIRE_HAS_SIZE) != 0)
+       {
+         if (u == NULL)
+           *iqp->size = -1;
+         else
+           {
+             sflush (u->s);
+             *iqp->size = ssize (u->s);
+           }
+       }
 
-  if ((cf2 & IOPARM_INQUIRE_HAS_ROUND) != 0)
-    {
-      if (u == NULL)
-       p = undefined;
-      else
-       switch (u->flags.round)
-         {
-         case ROUND_UP:
-           p = "UP";
-           break;
-         case ROUND_DOWN:
-           p = "DOWN";
-           break;
-         case ROUND_ZERO:
-           p = "ZERO";
-           break;
-         case ROUND_NEAREST:
-           p = "NEAREST";
-           break;
-         case ROUND_COMPATIBLE:
-           p = "COMPATIBLE";
-           break;
-         case ROUND_PROCDEFINED:
-           p = "PROCESSOR_DEFINED";
-           break;
-         default:
-           internal_error (&iqp->common, "inquire_via_unit(): Bad round");
-         }
+      if ((cf2 & IOPARM_INQUIRE_HAS_IQSTREAM) != 0)
+       {
+         if (u == NULL)
+           p = "UNKNOWN";
+         else
+           switch (u->flags.access)
+             {
+             case ACCESS_SEQUENTIAL:
+             case ACCESS_DIRECT:
+               p = no;
+               break;
+             case ACCESS_STREAM:
+               p = yes;
+               break;
+             default:
+               internal_error (&iqp->common, "inquire_via_unit(): Bad pad");
+             }
+    
+         cf_strcpy (iqp->iqstream, iqp->iqstream_len, p);
+       }
 
-      cf_strcpy (iqp->round, iqp->round_len, p);
+      if ((cf2 & IOPARM_INQUIRE_HAS_SHARE) != 0)
+       {
+         if (u == NULL)
+           p = "UNKNOWN";
+         else
+           switch (u->flags.share)
+             {
+               case SHARE_DENYRW:
+                 p = "DENYRW";
+                 break;
+               case SHARE_DENYNONE:
+                 p = "DENYNONE";
+                 break;
+               case SHARE_UNSPECIFIED:
+                 p = "NODENY";
+                 break;
+               default:
+                 internal_error (&iqp->common,
+                     "inquire_via_unit(): Bad share");
+                 break;
+             }
+
+         cf_strcpy (iqp->share, iqp->share_len, p);
+       }
+
+      if ((cf2 & IOPARM_INQUIRE_HAS_CC) != 0)
+       {
+         if (u == NULL)
+           p = "UNKNOWN";
+         else
+           switch (u->flags.cc)
+             {
+               case CC_FORTRAN:
+                 p = "FORTRAN";
+                 break;
+               case CC_LIST:
+                 p = "LIST";
+                 break;
+               case CC_NONE:
+                 p = "NONE";
+                 break;
+               case CC_UNSPECIFIED:
+                 p = "UNKNOWN";
+                 break;
+               default:
+                 internal_error (&iqp->common, "inquire_via_unit(): Bad cc");
+                 break;
+             }
+
+         cf_strcpy (iqp->cc, iqp->cc_len, p);
+       }
     }
 
   if ((cf & IOPARM_INQUIRE_HAS_POSITION) != 0)
@@ -379,24 +492,36 @@ inquire_via_unit (st_parameter_inquire *iqp, gfc_unit * u)
       if (u == NULL || u->flags.access == ACCESS_DIRECT)
         p = undefined;
       else
-        switch (u->flags.position)
-          {
-             case POSITION_REWIND:
-               p = "REWIND";
-               break;
-             case POSITION_APPEND:
-               p = "APPEND";
-               break;
-             case POSITION_ASIS:
-               p = "ASIS";
-               break;
-             default:
-               /* if not direct access, it must be
-                  either REWIND, APPEND, or ASIS.
-                  ASIS seems to be the best default */
-               p = "ASIS";
-               break;
-          }
+       {
+         /* If the position is unspecified, check if we can figure
+            out whether it's at the beginning or end.  */
+         if (u->flags.position == POSITION_UNSPECIFIED)
+           {
+             gfc_offset cur = stell (u->s);
+             if (cur == 0)
+               u->flags.position = POSITION_REWIND;
+             else if (cur != -1 && (ssize (u->s) == cur))
+               u->flags.position = POSITION_APPEND;
+           }
+         switch (u->flags.position)
+           {
+           case POSITION_REWIND:
+             p = "REWIND";
+             break;
+           case POSITION_APPEND:
+             p = "APPEND";
+             break;
+           case POSITION_ASIS:
+             p = "ASIS";
+             break;
+           default:
+             /* If the position has changed and is not rewind or
+                append, it must be set to a processor-dependent
+                value.  */
+             p = "UNSPECIFIED";
+             break;
+           }
+       }
       cf_strcpy (iqp->position, iqp->position_len, p);
     }
 
@@ -425,25 +550,19 @@ inquire_via_unit (st_parameter_inquire *iqp, gfc_unit * u)
 
   if ((cf & IOPARM_INQUIRE_HAS_READ) != 0)
     {
-      p = (u == NULL) ? inquire_read (NULL, 0) :
-       inquire_read (u->file, u->file_len);
-
+      p = (!u || u->flags.action == ACTION_WRITE) ? no : yes;
       cf_strcpy (iqp->read, iqp->read_len, p);
     }
 
   if ((cf & IOPARM_INQUIRE_HAS_WRITE) != 0)
     {
-      p = (u == NULL) ? inquire_write (NULL, 0) :
-       inquire_write (u->file, u->file_len);
-
+      p = (!u || u->flags.action == ACTION_READ) ? no : yes;
       cf_strcpy (iqp->write, iqp->write_len, p);
     }
 
   if ((cf & IOPARM_INQUIRE_HAS_READWRITE) != 0)
     {
-      p = (u == NULL) ? inquire_readwrite (NULL, 0) :
-       inquire_readwrite (u->file, u->file_len);
-
+      p = (!u || u->flags.action != ACTION_READWRITE) ? no : yes;
       cf_strcpy (iqp->readwrite, iqp->readwrite_len, p);
     }
 
@@ -455,6 +574,7 @@ inquire_via_unit (st_parameter_inquire *iqp, gfc_unit * u)
        switch (u->flags.delim)
          {
          case DELIM_NONE:
+         case DELIM_UNSPECIFIED:
            p = "NONE";
            break;
          case DELIM_QUOTE:
@@ -478,10 +598,10 @@ inquire_via_unit (st_parameter_inquire *iqp, gfc_unit * u)
        switch (u->flags.pad)
          {
          case PAD_NO:
-           p = "NO";
+           p = no;
            break;
          case PAD_YES:
-           p = "YES";
+           p = yes;
            break;
          default:
            internal_error (&iqp->common, "inquire_via_unit(): Bad pad");
@@ -497,13 +617,12 @@ inquire_via_unit (st_parameter_inquire *iqp, gfc_unit * u)
       else
        switch (u->flags.convert)
          {
-           /*  l8_to_l4_offset is 0 for little-endian, 1 for big-endian.  */
          case GFC_CONVERT_NATIVE:
-           p = l8_to_l4_offset ? "BIG_ENDIAN" : "LITTLE_ENDIAN";
+           p = __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ ? "BIG_ENDIAN" : "LITTLE_ENDIAN";
            break;
 
          case GFC_CONVERT_SWAP:
-           p = l8_to_l4_offset ? "LITTLE_ENDIAN" : "BIG_ENDIAN";
+           p = __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ ? "LITTLE_ENDIAN" : "BIG_ENDIAN";
            break;
 
          default:
@@ -516,14 +635,13 @@ inquire_via_unit (st_parameter_inquire *iqp, gfc_unit * u)
 
 
 /* inquire_via_filename()-- Inquiry via filename.  This subroutine is
* only used if the filename is *not* connected to a unit number. */
  only used if the filename is *not* connected to a unit number. */
 
 static void
 inquire_via_filename (st_parameter_inquire *iqp)
 {
   const char *p;
   GFC_INTEGER_4 cf = iqp->common.flags;
-  GFC_INTEGER_4 cf2 = iqp->flags2;
 
   if ((cf & IOPARM_INQUIRE_HAS_EXIST) != 0)
     *iqp->exist = file_exists (iqp->file, iqp->file_len);
@@ -582,14 +700,40 @@ inquire_via_filename (st_parameter_inquire *iqp)
   if ((cf & IOPARM_INQUIRE_HAS_PAD) != 0)
     cf_strcpy (iqp->pad, iqp->pad_len, undefined);
 
-  if ((cf2 & IOPARM_INQUIRE_HAS_ENCODING) != 0)
-    cf_strcpy (iqp->encoding, iqp->encoding_len, undefined);
+  if (cf & IOPARM_INQUIRE_HAS_FLAGS2)
+    {
+      GFC_INTEGER_4 cf2 = iqp->flags2;
+
+      if ((cf2 & IOPARM_INQUIRE_HAS_ENCODING) != 0)
+       cf_strcpy (iqp->encoding, iqp->encoding_len, undefined);
   
-  if ((cf2 & IOPARM_INQUIRE_HAS_DELIM) != 0)
-    cf_strcpy (iqp->delim, iqp->delim_len, undefined);
+      if ((cf2 & IOPARM_INQUIRE_HAS_DELIM) != 0)
+       cf_strcpy (iqp->delim, iqp->delim_len, undefined);
+
+      if ((cf2 & IOPARM_INQUIRE_HAS_DECIMAL) != 0)
+       cf_strcpy (iqp->decimal, iqp->decimal_len, undefined);
+
+      if ((cf2 & IOPARM_INQUIRE_HAS_DELIM) != 0)
+       cf_strcpy (iqp->delim, iqp->delim_len, undefined);
+
+      if ((cf2 & IOPARM_INQUIRE_HAS_PAD) != 0)
+       cf_strcpy (iqp->pad, iqp->pad_len, undefined);
+  
+      if ((cf2 & IOPARM_INQUIRE_HAS_ENCODING) != 0)
+       cf_strcpy (iqp->encoding, iqp->encoding_len, undefined);
+
+      if ((cf2 & IOPARM_INQUIRE_HAS_SIZE) != 0)
+       *iqp->size = file_size (iqp->file, iqp->file_len);
 
-  if ((cf2 & IOPARM_INQUIRE_HAS_DECIMAL) != 0)
-    cf_strcpy (iqp->decimal, iqp->decimal_len, undefined);
+      if ((cf2 & IOPARM_INQUIRE_HAS_IQSTREAM) != 0)
+       cf_strcpy (iqp->iqstream, iqp->iqstream_len, "UNKNOWN");
+
+      if ((cf2 & IOPARM_INQUIRE_HAS_SHARE) != 0)
+       cf_strcpy (iqp->share, iqp->share_len, "UNKNOWN");
+
+      if ((cf2 & IOPARM_INQUIRE_HAS_CC) != 0)
+       cf_strcpy (iqp->cc, iqp->cc_len, "UNKNOWN");
+    }
 
   if ((cf & IOPARM_INQUIRE_HAS_POSITION) != 0)
     cf_strcpy (iqp->position, iqp->position_len, undefined);
@@ -614,15 +758,6 @@ inquire_via_filename (st_parameter_inquire *iqp)
       p = inquire_read (iqp->file, iqp->file_len);
       cf_strcpy (iqp->readwrite, iqp->readwrite_len, p);
     }
-
-  if ((cf2 & IOPARM_INQUIRE_HAS_DELIM) != 0)
-    cf_strcpy (iqp->delim, iqp->delim_len, undefined);
-
-  if ((cf2 & IOPARM_INQUIRE_HAS_PAD) != 0)
-    cf_strcpy (iqp->pad, iqp->pad_len, undefined);
-  
-  if ((cf2 & IOPARM_INQUIRE_HAS_ENCODING) != 0)
-    cf_strcpy (iqp->encoding, iqp->encoding_len, undefined);
 }