PR sanitizer/65081
[official-gcc.git] / gcc / ada / a-zzboio.adb
blobc1efb2f7928e21c4c95e212d13d9790710662cb1
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT RUN-TIME COMPONENTS --
4 -- --
5 -- ADA.WIDE_WIDE_TEXT_IO.WIDE_WIDE_BOUNDED_IO --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 1997-2009, Free Software Foundation, Inc. --
10 -- --
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. --
17 -- --
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. --
21 -- --
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/>. --
26 -- --
27 -- GNAT was originally developed by the GNAT team at New York University. --
28 -- Extensive contributions were provided by Ada Core Technologies Inc. --
29 -- --
30 ------------------------------------------------------------------------------
32 with Ada.Wide_Wide_Text_IO; use Ada.Wide_Wide_Text_IO;
33 with Ada.Unchecked_Deallocation;
35 package body Ada.Wide_Wide_Text_IO.Wide_Wide_Bounded_IO is
37 type Wide_Wide_String_Access is access all Wide_Wide_String;
39 procedure Free (WWSA : in out Wide_Wide_String_Access);
40 -- Perform an unchecked deallocation of a non-null string
42 ----------
43 -- Free --
44 ----------
46 procedure Free (WWSA : in out Wide_Wide_String_Access) is
47 Null_Wide_Wide_String : constant Wide_Wide_String := "";
49 procedure Deallocate is
50 new Ada.Unchecked_Deallocation (
51 Wide_Wide_String, Wide_Wide_String_Access);
53 begin
54 -- Do not try to free statically allocated null string
56 if WWSA.all /= Null_Wide_Wide_String then
57 Deallocate (WWSA);
58 end if;
59 end Free;
61 --------------
62 -- Get_Line --
63 --------------
65 function Get_Line return Wide_Wide_Bounded.Bounded_Wide_Wide_String is
66 begin
67 return Wide_Wide_Bounded.To_Bounded_Wide_Wide_String (Get_Line);
68 end Get_Line;
70 --------------
71 -- Get_Line --
72 --------------
74 function Get_Line
75 (File : File_Type) return Wide_Wide_Bounded.Bounded_Wide_Wide_String
77 begin
78 return Wide_Wide_Bounded.To_Bounded_Wide_Wide_String (Get_Line (File));
79 end Get_Line;
81 --------------
82 -- Get_Line --
83 --------------
85 procedure Get_Line
86 (Item : out Wide_Wide_Bounded.Bounded_Wide_Wide_String)
88 Buffer : Wide_Wide_String (1 .. 1000);
89 Last : Natural;
90 Str1 : Wide_Wide_String_Access;
91 Str2 : Wide_Wide_String_Access;
93 begin
94 Get_Line (Buffer, Last);
95 Str1 := new Wide_Wide_String'(Buffer (1 .. Last));
97 while Last = Buffer'Last loop
98 Get_Line (Buffer, Last);
99 Str2 := new Wide_Wide_String'(Str1.all & Buffer (1 .. Last));
100 Free (Str1);
101 Str1 := Str2;
102 end loop;
104 Item := Wide_Wide_Bounded.To_Bounded_Wide_Wide_String (Str1.all);
105 end Get_Line;
107 --------------
108 -- Get_Line --
109 --------------
111 procedure Get_Line
112 (File : File_Type;
113 Item : out Wide_Wide_Bounded.Bounded_Wide_Wide_String)
115 Buffer : Wide_Wide_String (1 .. 1000);
116 Last : Natural;
117 Str1 : Wide_Wide_String_Access;
118 Str2 : Wide_Wide_String_Access;
120 begin
121 Get_Line (File, Buffer, Last);
122 Str1 := new Wide_Wide_String'(Buffer (1 .. Last));
124 while Last = Buffer'Last loop
125 Get_Line (File, Buffer, Last);
126 Str2 := new Wide_Wide_String'(Str1.all & Buffer (1 .. Last));
127 Free (Str1);
128 Str1 := Str2;
129 end loop;
131 Item := Wide_Wide_Bounded.To_Bounded_Wide_Wide_String (Str1.all);
132 end Get_Line;
134 ---------
135 -- Put --
136 ---------
138 procedure Put
139 (Item : Wide_Wide_Bounded.Bounded_Wide_Wide_String)
141 begin
142 Put (Wide_Wide_Bounded.To_Wide_Wide_String (Item));
143 end Put;
145 ---------
146 -- Put --
147 ---------
149 procedure Put
150 (File : File_Type;
151 Item : Wide_Wide_Bounded.Bounded_Wide_Wide_String)
153 begin
154 Put (File, Wide_Wide_Bounded.To_Wide_Wide_String (Item));
155 end Put;
157 --------------
158 -- Put_Line --
159 --------------
161 procedure Put_Line
162 (Item : Wide_Wide_Bounded.Bounded_Wide_Wide_String)
164 begin
165 Put_Line (Wide_Wide_Bounded.To_Wide_Wide_String (Item));
166 end Put_Line;
168 --------------
169 -- Put_Line --
170 --------------
172 procedure Put_Line
173 (File : File_Type;
174 Item : Wide_Wide_Bounded.Bounded_Wide_Wide_String)
176 begin
177 Put_Line (File, Wide_Wide_Bounded.To_Wide_Wide_String (Item));
178 end Put_Line;
180 end Ada.Wide_Wide_Text_IO.Wide_Wide_Bounded_IO;