* config/arm/elf.h (ASM_OUTPUT_ALIGNED_COMMON): Remove definition.
[official-gcc.git] / gcc / ada / 6vcstrea.adb
blob20379da30acd350a0c648919562cd89983ce5ebc
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- I N T E R F A C E S . C _ S T R E A M S --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 1996-2002 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 2, 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. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING. If not, write --
19 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
20 -- MA 02111-1307, USA. --
21 -- --
22 -- As a special exception, if other files instantiate generics from this --
23 -- unit, or you link this unit with other files to produce an executable, --
24 -- this unit does not by itself cause the resulting executable to be --
25 -- covered by the GNU General Public License. This exception does not --
26 -- however invalidate any other reasons why the executable file might be --
27 -- covered by the GNU Public License. --
28 -- --
29 -- GNAT was originally developed by the GNAT team at New York University. --
30 -- Extensive contributions were provided by Ada Core Technologies Inc. --
31 -- --
32 ------------------------------------------------------------------------------
34 -- This is the Alpha/VMS version.
36 with Unchecked_Conversion;
37 package body Interfaces.C_Streams is
39 ------------
40 -- fread --
41 ------------
43 function fread
44 (buffer : voids;
45 size : size_t;
46 count : size_t;
47 stream : FILEs)
48 return size_t
50 Get_Count : size_t := 0;
51 type Buffer_Type is array (size_t range 1 .. count,
52 size_t range 1 .. size) of Character;
53 type Buffer_Access is access Buffer_Type;
54 function To_BA is new Unchecked_Conversion (voids, Buffer_Access);
55 BA : Buffer_Access := To_BA (buffer);
56 Ch : int;
57 begin
59 -- This Fread goes with the Fwrite below.
60 -- The C library fread sometimes can't read fputc generated files.
62 for C in 1 .. count loop
63 for S in 1 .. size loop
64 Ch := fgetc (stream);
65 if Ch = EOF then
66 return 0;
67 end if;
68 BA.all (C, S) := Character'Val (Ch);
69 end loop;
70 Get_Count := Get_Count + 1;
71 end loop;
72 return Get_Count;
73 end fread;
75 ------------
76 -- fread --
77 ------------
79 function fread
80 (buffer : voids;
81 index : size_t;
82 size : size_t;
83 count : size_t;
84 stream : FILEs)
85 return size_t
87 Get_Count : size_t := 0;
88 type Buffer_Type is array (size_t range 1 .. count,
89 size_t range 1 .. size) of Character;
90 type Buffer_Access is access Buffer_Type;
91 function To_BA is new Unchecked_Conversion (voids, Buffer_Access);
92 BA : Buffer_Access := To_BA (buffer);
93 Ch : int;
94 begin
96 -- This Fread goes with the Fwrite below.
97 -- The C library fread sometimes can't read fputc generated files.
99 for C in 1 + index .. count + index loop
100 for S in 1 .. size loop
101 Ch := fgetc (stream);
102 if Ch = EOF then
103 return 0;
104 end if;
105 BA.all (C, S) := Character'Val (Ch);
106 end loop;
107 Get_Count := Get_Count + 1;
108 end loop;
109 return Get_Count;
110 end fread;
112 ------------
113 -- fwrite --
114 ------------
116 function fwrite
117 (buffer : voids;
118 size : size_t;
119 count : size_t;
120 stream : FILEs)
121 return size_t
123 Put_Count : size_t := 0;
124 type Buffer_Type is array (size_t range 1 .. count,
125 size_t range 1 .. size) of Character;
126 type Buffer_Access is access Buffer_Type;
127 function To_BA is new Unchecked_Conversion (voids, Buffer_Access);
128 BA : Buffer_Access := To_BA (buffer);
129 begin
131 -- Fwrite on VMS has the undesirable effect of always generating at
132 -- least one record of output per call, regardless of buffering. To
133 -- get around this, we do multiple fputc calls instead.
135 for C in 1 .. count loop
136 for S in 1 .. size loop
137 if fputc (Character'Pos (BA.all (C, S)), stream) = EOF then
138 exit;
139 end if;
140 end loop;
141 Put_Count := Put_Count + 1;
142 end loop;
143 return Put_Count;
144 end fwrite;
146 -------------
147 -- setvbuf --
148 -------------
150 function setvbuf
151 (stream : FILEs;
152 buffer : chars;
153 mode : int;
154 size : size_t)
155 return int
157 function C_setvbuf
158 (stream : FILEs;
159 buffer : chars;
160 mode : int;
161 size : size_t)
162 return int;
163 pragma Import (C, C_setvbuf, "setvbuf");
165 use type System.Address;
166 begin
168 -- In order for the above fwrite hack to work, we must always buffer
169 -- stdout and stderr. Is_regular_file on VMS cannot detect when
170 -- these are redirected to a file, so checking for that condition
171 -- doesn't help.
173 if mode = IONBF
174 and then (stream = stdout or else stream = stderr)
175 then
176 return C_setvbuf (stream, buffer, IOLBF, size);
177 else
178 return C_setvbuf (stream, buffer, mode, size);
179 end if;
180 end setvbuf;
182 end Interfaces.C_Streams;