]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR fortran/44931 (For INPUT_UNIT, INQUIRE NAME= should not return "stdin")
authorJerry DeLisle <jvdelisle@gcc.gnu.org>
Thu, 29 Jul 2010 01:32:23 +0000 (01:32 +0000)
committerJerry DeLisle <jvdelisle@gcc.gnu.org>
Thu, 29 Jul 2010 01:32:23 +0000 (01:32 +0000)
2010-07-28  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

PR libfortran/44931
* io/inquire.c (inquire_via_unit): Use ttyname to return actual device
file name for stdin, stdout, and stderr.  If ttyname does not succeed
fall back to default names for these units. Include string.h to allow
using strlen function.
* unix.c: Remove typedef of unix_stream structure, move to unix.h.
* unix.h: Add typedef of unix_stream structure so that it is
accessible to inquire.c.

From-SVN: r162667

libgfortran/ChangeLog
libgfortran/io/inquire.c
libgfortran/io/unix.c
libgfortran/io/unix.h

index 9252a90f46dc4556ea86d0d5bcd9044599e0a73f..25581552e5e78079e1b196f71931fa12385da6b5 100644 (file)
@@ -1,3 +1,14 @@
+2010-07-28  Jerry DeLisle  <jvdelisle@gcc.gnu.org>
+
+       PR libfortran/44931
+       * io/inquire.c (inquire_via_unit): Use ttyname to return actual device
+       file name for stdin, stdout, and stderr.  If ttyname does not succeed
+       fall back to default names for these units. Include string.h to allow
+       using strlen function.
+       * unix.c: Remove typedef of unix_stream structure, move to unix.h.
+       * unix.h: Add typedef of unix_stream structure so that it is
+       accessible to inquire.c.
+
 2010-07-19  Jerry DeLisle  <jvdelisle@gcc.gnu.org>
 
        PR libfortran/44953
index f908cde0ccf692d68c9db8a6d97a09053a19ec28..1189c544b3538aef5115886d2dbf003253d99237 100644 (file)
@@ -26,6 +26,7 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 
 /* Implement the non-IOLENGTH variant of the INQUIRY statement */
 
+#include <string.h>
 #include "io.h"
 #include "unix.h"
 
@@ -66,7 +67,25 @@ 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);
+    {
+#ifdef HAVE_TTYNAME
+      if (u->unit_number == options.stdin_unit
+         || u->unit_number == options.stdout_unit
+         || u->unit_number == options.stderr_unit)
+       {
+         char * tmp = ttyname (((unix_stream *) u->s)->fd);
+         if (tmp != NULL)
+           {
+             int tmplen = strlen (tmp);
+             fstrcpy (iqp->name, iqp->name_len, tmp, tmplen);
+           }
+         else /* If ttyname does not work, go with the default.  */
+           fstrcpy (iqp->name, iqp->name_len, u->file, u->file_len);
+       }
+      else
+#endif
+       fstrcpy (iqp->name, iqp->name_len, u->file, u->file_len);
+    }
 
   if ((cf & IOPARM_INQUIRE_HAS_ACCESS) != 0)
     {
index 3a795aef53624d6c87c5aab1b1315cddbb841a9c..eea03ba7f819618ff40f26c6bba5f7d15cacfb35 100644 (file)
@@ -135,28 +135,6 @@ typedef struct stat gfstat_t;
 
 static const int BUFFER_SIZE = 8192;
 
-typedef struct
-{
-  stream st;
-
-  gfc_offset buffer_offset;    /* File offset of the start of the buffer */
-  gfc_offset physical_offset;  /* Current physical file offset */
-  gfc_offset logical_offset;   /* Current logical file offset */
-  gfc_offset file_length;      /* Length of the file, -1 if not seekable. */
-
-  char *buffer;                 /* Pointer to the buffer.  */
-  int fd;                       /* The POSIX file descriptor.  */
-
-  int active;                  /* Length of valid bytes in the buffer */
-
-  int prot;
-  int ndirty;                  /* Dirty bytes starting at buffer_offset */
-
-  int special_file;            /* =1 if the fd refers to a special file */
-}
-unix_stream;
-
-
 /* fix_fd()-- Given a file descriptor, make sure it is not one of the
  * standard descriptors, returning a non-standard descriptor.  If the
  * user specifies that system errors should go to standard output,
index 3229d502547f1e1a38555297082db3b5e03aa92b..dc433d75a8ae01ad9dc6b0528e53849e8128d8a3 100644 (file)
@@ -41,6 +41,29 @@ struct stream
   int (*close) (struct stream *);
 };
 
+
+typedef struct
+{
+  stream st;
+
+  gfc_offset buffer_offset;    /* File offset of the start of the buffer */
+  gfc_offset physical_offset;  /* Current physical file offset */
+  gfc_offset logical_offset;   /* Current logical file offset */
+  gfc_offset file_length;      /* Length of the file, -1 if not seekable. */
+
+  char *buffer;                 /* Pointer to the buffer.  */
+  int fd;                       /* The POSIX file descriptor.  */
+
+  int active;                  /* Length of valid bytes in the buffer */
+
+  int prot;
+  int ndirty;                  /* Dirty bytes starting at buffer_offset */
+
+  int special_file;            /* =1 if the fd refers to a special file */
+}
+unix_stream;
+
+
 /* Inline functions for doing file I/O given a stream.  */
 static inline ssize_t
 sread (stream * s, void * buf, ssize_t nbyte)