1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
5 -- I N T E R F A C E S . C _ S T R E A M S --
9 -- Copyright (C) 1996-2002 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 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. --
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. --
29 -- GNAT was originally developed by the GNAT team at New York University. --
30 -- Extensive contributions were provided by Ada Core Technologies Inc. --
32 ------------------------------------------------------------------------------
34 -- This is the Alpha/VMS version.
36 with Unchecked_Conversion;
37 package body Interfaces.C_Streams is
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);
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
68 BA.all (C, S) := Character'Val (Ch);
70 Get_Count := Get_Count + 1;
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);
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);
105 BA.all (C, S) := Character'Val (Ch);
107 Get_Count := Get_Count + 1;
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);
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
141 Put_Count := Put_Count + 1;
163 pragma Import (C, C_setvbuf, "setvbuf");
165 use type System.Address;
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
174 and then (stream = stdout or else stream = stderr)
176 return C_setvbuf (stream, buffer, IOLBF, size);
178 return C_setvbuf (stream, buffer, mode, size);
182 end Interfaces.C_Streams;