From patchwork Sun Jul 25 00:56:03 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerry DeLisle X-Patchwork-Id: 59865 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id B1AA3B6F0E for ; Sun, 25 Jul 2010 10:56:26 +1000 (EST) Received: (qmail 32759 invoked by alias); 25 Jul 2010 00:56:24 -0000 Received: (qmail 32733 invoked by uid 22791); 25 Jul 2010 00:56:22 -0000 X-SWARE-Spam-Status: No, hits=3.1 required=5.0 tests=AWL, BAYES_00, BOTNET, RCVD_IN_DNSWL_NONE, TW_CP, TW_IQ, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from vms173019pub.verizon.net (HELO vms173019pub.verizon.net) (206.46.173.19) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sun, 25 Jul 2010 00:56:17 +0000 Received: from [192.168.1.10] ([unknown] [64.234.92.14]) by vms173019.mailsrvcs.net (Sun Java(tm) System Messaging Server 7u2-7.02 32bit (built Apr 16 2009)) with ESMTPA id <0L63008O599FVN26@vms173019.mailsrvcs.net>; Sat, 24 Jul 2010 19:56:05 -0500 (CDT) Message-id: <4C4B8BA3.2070202@verizon.net> Date: Sat, 24 Jul 2010 17:56:03 -0700 From: Jerry DeLisle User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.10) Gecko/20100527 Thunderbird/3.0.5 MIME-version: 1.0 To: gfortran Cc: gcc patches Subject: [patch, libfortran] PR44931 For INPUT_UNIT, INQUIRE NAME= should not return "stdin" Content-type: multipart/mixed; boundary=------------080609020209050202050901 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Hi Folks, The attach patch uses ttyname to return the device file name for inquire by unit. Regression tested on x86-64. Test case attached, but the reulst are system dependent so I will not add it to the testsuite. OK for trunk? Regards, Jerry 2010-07-24 Jerry DeLisle 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. program test_inquire character(80) :: str1 open(10, file="myfilename") str1 = "" inquire(unit=6, name=str1) print *, 1,str1 str1 = "" inquire(unit=5, name=str1) print *, 2,str1 str1 = "" inquire(unit=37, name=str1) print *, 3,str1 str1 = "" ! Empty string since no connection has been made to unit 37 inquire(unit=10, name=str1) print *, 4,str1 open(6,file="test.dat") inquire(6,name=str1) if (str1 /= "test.dat") call abort() open(6,file="/dev/pts/2") print *, 5,str1 end program test_inquire Index: inquire.c =================================================================== --- inquire.c (revision 162497) +++ inquire.c (working copy) @@ -26,6 +26,7 @@ see the files COPYING3 and COPYING.RUNTIME respect /* Implement the non-IOLENGTH variant of the INQUIRY statement */ +#include #include "io.h" #include "unix.h" @@ -66,7 +67,23 @@ inquire_via_unit (st_parameter_inquire *iqp, gfc_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 (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 + fstrcpy (iqp->name, iqp->name_len, u->file, u->file_len); + } if ((cf & IOPARM_INQUIRE_HAS_ACCESS) != 0) { Index: unix.c =================================================================== --- unix.c (revision 162497) +++ unix.c (working copy) @@ -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: unix.h =================================================================== --- unix.h (revision 162497) +++ unix.h (working copy) @@ -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)