1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
5 -- I N T E R F A C E S . C _ S T R E A M S --
11 -- Copyright (C) 1996-1999 Free Software Foundation, Inc. --
13 -- GNAT is free software; you can redistribute it and/or modify it under --
14 -- terms of the GNU General Public License as published by the Free Soft- --
15 -- ware Foundation; either version 2, or (at your option) any later ver- --
16 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
17 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
18 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
19 -- for more details. You should have received a copy of the GNU General --
20 -- Public License distributed with GNAT; see file COPYING. If not, write --
21 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
22 -- MA 02111-1307, USA. --
24 -- As a special exception, if other files instantiate generics from this --
25 -- unit, or you link this unit with other files to produce an executable, --
26 -- this unit does not by itself cause the resulting executable to be --
27 -- covered by the GNU General Public License. This exception does not --
28 -- however invalidate any other reasons why the executable file might be --
29 -- covered by the GNU Public License. --
31 -- GNAT was originally developed by the GNAT team at New York University. --
32 -- It is now maintained by Ada Core Technologies Inc (http://www.gnat.com). --
34 ------------------------------------------------------------------------------
36 -- This is the Alpha/VMS version.
38 package body Interfaces
.C_Streams
is
51 Get_Count
: size_t
:= 0;
52 type Buffer_Type
is array (size_t
range 1 .. count
,
53 size_t
range 1 .. size
) of Character;
54 type Buffer_Access
is access Buffer_Type
;
55 function To_BA
is new Unchecked_Conversion
(voids
, Buffer_Access
);
56 BA
: Buffer_Access
:= To_BA
(buffer
);
60 -- This Fread goes with the Fwrite below.
61 -- The C library fread sometimes can't read fputc generated files.
63 for C
in 1 .. count
loop
64 for S
in 1 .. size
loop
69 BA
.all (C
, S
) := Character'Val (Ch
);
71 Get_Count
:= Get_Count
+ 1;
88 Get_Count
: size_t
:= 0;
89 type Buffer_Type
is array (size_t
range 1 .. count
,
90 size_t
range 1 .. size
) of Character;
91 type Buffer_Access
is access Buffer_Type
;
92 function To_BA
is new Unchecked_Conversion
(voids
, Buffer_Access
);
93 BA
: Buffer_Access
:= To_BA
(buffer
);
97 -- This Fread goes with the Fwrite below.
98 -- The C library fread sometimes can't read fputc generated files.
100 for C
in 1 + index
.. count
+ index
loop
101 for S
in 1 .. size
loop
102 Ch
:= fgetc
(stream
);
106 BA
.all (C
, S
) := Character'Val (Ch
);
108 Get_Count
:= Get_Count
+ 1;
124 Put_Count
: size_t
:= 0;
125 type Buffer_Type
is array (size_t
range 1 .. count
,
126 size_t
range 1 .. size
) of Character;
127 type Buffer_Access
is access Buffer_Type
;
128 function To_BA
is new Unchecked_Conversion
(voids
, Buffer_Access
);
129 BA
: Buffer_Access
:= To_BA
(buffer
);
132 -- Fwrite on VMS has the undesirable effect of always generating at
133 -- least one record of output per call, regardless of buffering. To
134 -- get around this, we do multiple fputc calls instead.
136 for C
in 1 .. count
loop
137 for S
in 1 .. size
loop
138 if fputc
(Character'Pos (BA
.all (C
, S
)), stream
) = EOF
then
142 Put_Count
:= Put_Count
+ 1;
164 pragma Import
(C
, C_setvbuf
, "setvbuf");
166 use type System
.Address
;
169 -- In order for the above fwrite hack to work, we must always buffer
170 -- stdout and stderr. Is_regular_file on VMS cannot detect when
171 -- these are redirected to a file, so checking for that condition
175 and then (stream
= stdout
or else stream
= stderr
)
177 return C_setvbuf
(stream
, buffer
, IOLBF
, size
);
179 return C_setvbuf
(stream
, buffer
, mode
, size
);
183 end Interfaces
.C_Streams
;