Disable tests for strdup/strndup on __hpux__
[official-gcc.git] / gcc / ada / libgnat / a-tideio__128.adb
blob19bcf7499e19dde93ecb108e2109f64ed6711a85
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT RUN-TIME COMPONENTS --
4 -- --
5 -- A D A . T E X T _ I O . D E C I M A L _ I O --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 2020-2023, 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 Interfaces;
33 with Ada.Text_IO.Decimal_Aux;
34 with System.Img_Decimal_32; use System.Img_Decimal_32;
35 with System.Img_Decimal_64; use System.Img_Decimal_64;
36 with System.Img_Decimal_128; use System.Img_Decimal_128;
37 with System.Val_Decimal_32; use System.Val_Decimal_32;
38 with System.Val_Decimal_64; use System.Val_Decimal_64;
39 with System.Val_Decimal_128; use System.Val_Decimal_128;
41 package body Ada.Text_IO.Decimal_IO is
43 subtype Int32 is Interfaces.Integer_32;
44 subtype Int64 is Interfaces.Integer_64;
45 subtype Int128 is Interfaces.Integer_128;
47 package Aux32 is new
48 Ada.Text_IO.Decimal_Aux
49 (Int32,
50 Scan_Decimal32,
51 Set_Image_Decimal32);
53 package Aux64 is new
54 Ada.Text_IO.Decimal_Aux
55 (Int64,
56 Scan_Decimal64,
57 Set_Image_Decimal64);
59 package Aux128 is new
60 Ada.Text_IO.Decimal_Aux
61 (Int128,
62 Scan_Decimal128,
63 Set_Image_Decimal128);
65 Need64 : constant Boolean := Num'Size > 32;
66 Need128 : constant Boolean := Num'Size > 64;
67 -- Throughout this generic body, we distinguish between the case where type
68 -- Int32 is acceptable, where type Int64 is acceptable and where an Int128
69 -- is needed. These boolean constants are used to test for these cases and
70 -- since it is a constant, only code for the relevant case will be included
71 -- in the instance.
73 Scale : constant Integer := Num'Scale;
75 ---------
76 -- Get --
77 ---------
79 procedure Get
80 (File : File_Type;
81 Item : out Num;
82 Width : Field := 0)
84 pragma Unsuppress (Range_Check);
86 begin
87 if Need128 then
88 Item := Num'Fixed_Value (Aux128.Get (File, Width, Scale));
89 elsif Need64 then
90 Item := Num'Fixed_Value (Aux64.Get (File, Width, Scale));
91 else
92 Item := Num'Fixed_Value (Aux32.Get (File, Width, Scale));
93 end if;
95 exception
96 when Constraint_Error => raise Data_Error;
97 end Get;
99 procedure Get
100 (Item : out Num;
101 Width : Field := 0)
103 begin
104 Get (Current_In, Item, Width);
105 end Get;
107 procedure Get
108 (From : String;
109 Item : out Num;
110 Last : out Positive)
112 pragma Unsuppress (Range_Check);
114 begin
115 if Need128 then
116 Item := Num'Fixed_Value (Aux128.Gets (From, Last, Scale));
117 elsif Need64 then
118 Item := Num'Fixed_Value (Aux64.Gets (From, Last, Scale));
119 else
120 Item := Num'Fixed_Value (Aux32.Gets (From, Last, Scale));
121 end if;
123 exception
124 when Constraint_Error => raise Data_Error;
125 end Get;
127 ---------
128 -- Put --
129 ---------
131 procedure Put
132 (File : File_Type;
133 Item : Num;
134 Fore : Field := Default_Fore;
135 Aft : Field := Default_Aft;
136 Exp : Field := Default_Exp)
138 begin
139 if Need128 then
140 Aux128.Put
141 (File, Int128'Integer_Value (Item), Fore, Aft, Exp, Scale);
142 elsif Need64 then
143 Aux64.Put
144 (File, Int64'Integer_Value (Item), Fore, Aft, Exp, Scale);
145 else
146 Aux32.Put
147 (File, Int32'Integer_Value (Item), Fore, Aft, Exp, Scale);
148 end if;
149 end Put;
151 procedure Put
152 (Item : Num;
153 Fore : Field := Default_Fore;
154 Aft : Field := Default_Aft;
155 Exp : Field := Default_Exp)
157 begin
158 Put (Current_Out, Item, Fore, Aft, Exp);
159 end Put;
161 procedure Put
162 (To : out String;
163 Item : Num;
164 Aft : Field := Default_Aft;
165 Exp : Field := Default_Exp)
167 begin
168 if Need128 then
169 Aux128.Puts (To, Int128'Integer_Value (Item), Aft, Exp, Scale);
170 elsif Need64 then
171 Aux64.Puts (To, Int64'Integer_Value (Item), Aft, Exp, Scale);
172 else
173 Aux32.Puts (To, Int32'Integer_Value (Item), Aft, Exp, Scale);
174 end if;
175 end Put;
177 end Ada.Text_IO.Decimal_IO;