1 ------------------------------------------------------------------------------
3 -- GNAT RUN-TIME COMPONENTS --
5 -- ADA.STRINGS.TEXT_BUFFERS.FILES --
9 -- Copyright (C) 2020-2023, Free Software Foundation, Inc. --
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 Ada
.Finalization
;
35 package Ada
.Strings
.Text_Buffers
.Files
is
37 type File_Buffer
is new Root_Buffer_Type
with private;
38 -- Output written to a File_Buffer is written to the associated file.
40 function Create_From_FD
41 (FD
: System
.OS_Lib
.File_Descriptor
;
42 Close_Upon_Finalization
: Boolean := True)
44 -- file closed upon finalization if specified
46 function Create_File
(Name
: String) return File_Buffer
;
47 -- file closed upon finalization
49 function Create_Standard_Output_Buffer
return File_Buffer
is
50 (Create_From_FD
(System
.OS_Lib
.Standout
,
51 Close_Upon_Finalization
=> False));
52 function Create_Standard_Error_Buffer
return File_Buffer
is
53 (Create_From_FD
(System
.OS_Lib
.Standerr
,
54 Close_Upon_Finalization
=> False));
58 procedure Put_UTF_8_Implementation
59 (Buffer
: in out Root_Buffer_Type
'Class;
60 Item
: UTF_Encoding
.UTF_8_String
)
61 with Pre
=> Buffer
in File_Buffer
'Class;
63 package Mapping
is new Output_Mapping
(Put_UTF_8_Implementation
);
65 package OS
renames System
.OS_Lib
;
67 type Self_Ref
(Self
: not null access File_Buffer
)
68 is new Finalization
.Limited_Controlled
with null record;
69 overriding
procedure Finalize
(Ref
: in out Self_Ref
);
71 type File_Buffer
is new Mapping
.Buffer_Type
with record
72 FD
: OS
.File_Descriptor
:= OS
.Invalid_FD
;
73 Ref
: Self_Ref
(File_Buffer
'Access);
74 Close_Upon_Finalization
: Boolean := False;
77 end Ada
.Strings
.Text_Buffers
.Files
;