2005-08-31 J"orn Rennecke <joern.rennecke@st.com>
[official-gcc.git] / libgfortran / intrinsics / tty.c
blob3a3d2bdb98c7a4b7a8401280f88efe96c5c0fda8
1 /* Implementation of the ISATTY and TTYNAM g77 intrinsics.
2 Copyright (C) 2005 Free Software Foundation, Inc.
3 Contributed by François-Xavier Coudert <coudert@clipper.ens.fr>
5 This file is part of the GNU Fortran 95 runtime library (libgfortran).
7 Libgfortran is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public
9 License as published by the Free Software Foundation; either
10 version 2 of the License, or (at your option) any later version.
12 In addition to the permissions in the GNU General Public License, the
13 Free Software Foundation gives you unlimited permission to link the
14 compiled version of this file into combinations with other programs,
15 and to distribute those combinations without any restriction coming
16 from the use of this file. (The General Public License restrictions
17 do apply in other respects; for example, they cover modification of
18 the file, and distribution when not linked into a combine
19 executable.)
21 Libgfortran is distributed in the hope that it will be useful,
22 but WITHOUT ANY WARRANTY; without even the implied warranty of
23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 GNU General Public License for more details.
26 You should have received a copy of the GNU General Public
27 License along with libgfortran; see the file COPYING. If not,
28 write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
29 Boston, MA 02110-1301, USA. */
31 #include "config.h"
32 #include "libgfortran.h"
33 #include "../io/io.h"
34 #include <string.h>
36 /* LOGICAL FUNCTION ISATTY(UNIT)
37 INTEGER, INTENT(IN) :: UNIT */
39 extern GFC_LOGICAL_4 isatty_l4 (int *);
40 export_proto(isatty_l4);
42 GFC_LOGICAL_4
43 isatty_l4 (int *unit)
45 gfc_unit *u;
47 u = find_unit (*unit);
48 if (u != NULL)
49 return (GFC_LOGICAL_4) stream_isatty (u->s);
50 else
51 return 0;
55 extern GFC_LOGICAL_8 isatty_l8 (int *);
56 export_proto(isatty_l8);
58 GFC_LOGICAL_8
59 isatty_l8 (int *unit)
61 gfc_unit *u;
63 u = find_unit (*unit);
64 if (u != NULL)
65 return (GFC_LOGICAL_8) stream_isatty (u->s);
66 else
67 return 0;
71 /* SUBROUTINE TTYNAM(UNIT,NAME)
72 INTEGER,SCALAR,INTENT(IN) :: UNIT
73 CHARACTER,SCALAR,INTENT(OUT) :: NAME */
75 extern void ttynam_sub (int *, char *, gfc_charlen_type);
76 export_proto(ttynam_sub);
78 void
79 ttynam_sub (int *unit, char * name, gfc_charlen_type name_len)
81 gfc_unit *u;
82 char * n;
83 int i;
85 memset (name, ' ', name_len);
86 u = find_unit (*unit);
87 if (u != NULL)
89 n = stream_ttyname (u->s);
90 if (n != NULL)
92 i = 0;
93 while (*n && i < name_len)
94 name[i++] = *(n++);