1 ------------------------------------------------------------------------------
3 -- GNAT LIBRARY COMPONENTS --
9 -- Copyright (C) 2002-2011, AdaCore --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. --
18 -- As a special exception under Section 7 of GPL version 3, you are granted --
19 -- additional permissions described in the GCC Runtime Library Exception, --
20 -- version 3.1, as published by the Free Software Foundation. --
22 -- You should have received a copy of the GNU General Public License and --
23 -- a copy of the GCC Runtime Library Exception along with this program; --
24 -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
25 -- <http://www.gnu.org/licenses/>. --
27 -- GNAT was originally developed by the GNAT team at New York University. --
28 -- Extensive contributions were provided by Ada Core Technologies Inc. --
30 ------------------------------------------------------------------------------
32 with Interfaces
.C
.Strings
; use Interfaces
.C
.Strings
;
34 package body GNAT
.TTY
is
38 procedure Check_TTY
(Handle
: TTY_Handle
);
39 -- Check the validity of Handle. Raise Program_Error if ttys are not
40 -- supported. Raise Constraint_Error if Handle is an invalid handle.
46 procedure Allocate_TTY
(Handle
: out TTY_Handle
) is
47 function Internal
return System
.Address
;
48 pragma Import
(C
, Internal
, "__gnat_new_tty");
51 if not TTY_Supported
then
55 Handle
.Handle
:= Internal
;
62 procedure Check_TTY
(Handle
: TTY_Handle
) is
64 if not TTY_Supported
then
66 elsif Handle
.Handle
= System
.Null_Address
then
67 raise Constraint_Error
;
75 procedure Close_TTY
(Handle
: in out TTY_Handle
) is
76 procedure Internal
(Handle
: System
.Address
);
77 pragma Import
(C
, Internal
, "__gnat_close_tty");
80 Internal
(Handle
.Handle
);
81 Handle
.Handle
:= System
.Null_Address
;
88 procedure Reset_TTY
(Handle
: TTY_Handle
) is
89 procedure Internal
(Handle
: System
.Address
);
90 pragma Import
(C
, Internal
, "__gnat_reset_tty");
93 Internal
(Handle
.Handle
);
100 function TTY_Descriptor
101 (Handle
: TTY_Handle
) return GNAT
.OS_Lib
.File_Descriptor
104 (Handle
: System
.Address
) return GNAT
.OS_Lib
.File_Descriptor
;
105 pragma Import
(C
, Internal
, "__gnat_tty_fd");
108 return Internal
(Handle
.Handle
);
115 function TTY_Name
(Handle
: TTY_Handle
) return String is
116 function Internal
(Handle
: System
.Address
) return chars_ptr
;
117 pragma Import
(C
, Internal
, "__gnat_tty_name");
120 return Value
(Internal
(Handle
.Handle
));
127 function TTY_Supported
return Boolean is
128 function Internal
return Integer;
129 pragma Import
(C
, Internal
, "__gnat_tty_supported");
131 return Internal
/= 0;