Dead
[official-gcc.git] / gomp-20050608-branch / gcc / ada / i-cstrea.adb
bloba81bfdfe451e2a9061294f6a325981e54a993102
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-2003 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, 51 Franklin Street, Fifth Floor, --
20 -- Boston, MA 02110-1301, 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 default version which just calls the C versions directly
35 -- Note: the reason that we provide for specialization here is that on
36 -- some systems, notably VMS, we may need to worry about buffering.
38 with Unchecked_Conversion;
40 package body Interfaces.C_Streams is
42 use type System.CRTL.size_t;
44 ----------------------------
45 -- Interfaced C functions --
46 ----------------------------
48 function C_fread
49 (buffer : voids;
50 size : size_t;
51 count : size_t;
52 stream : FILEs) return size_t;
53 pragma Import (C, C_fread, "fread");
55 function C_fwrite
56 (buffer : voids;
57 size : size_t;
58 count : size_t;
59 stream : FILEs) return size_t;
60 pragma Import (C, C_fwrite, "fwrite");
62 function C_setvbuf
63 (stream : FILEs;
64 buffer : chars;
65 mode : int;
66 size : size_t) return int;
67 pragma Import (C, C_setvbuf, "setvbuf");
69 ------------
70 -- fread --
71 ------------
73 function fread
74 (buffer : voids;
75 size : size_t;
76 count : size_t;
77 stream : FILEs) return size_t
79 begin
80 return C_fread (buffer, size, count, stream);
81 end fread;
83 ------------
84 -- fread --
85 ------------
87 -- The following declarations should really be nested within fread, but
88 -- limitations in front end inlining make this undesirable right now ???
90 type Byte_Buffer is array (0 .. size_t'Last / 2 - 1) of Unsigned_8;
91 -- This should really be 0 .. size_t'last, but there is a problem
92 -- in gigi in handling such types (introduced in GCC 3 Sep 2001)
93 -- since the size in bytes of this array overflows ???
95 type Acc_Bytes is access all Byte_Buffer;
97 function To_Acc_Bytes is new Unchecked_Conversion (voids, Acc_Bytes);
99 function fread
100 (buffer : voids;
101 index : size_t;
102 size : size_t;
103 count : size_t;
104 stream : FILEs) return size_t
106 begin
107 return C_fread
108 (To_Acc_Bytes (buffer) (index * size)'Address, size, count, stream);
109 end fread;
111 ------------
112 -- fwrite --
113 ------------
115 function fwrite
116 (buffer : voids;
117 size : size_t;
118 count : size_t;
119 stream : FILEs) return size_t
121 begin
122 return C_fwrite (buffer, size, count, stream);
123 end fwrite;
125 -------------
126 -- setvbuf --
127 -------------
129 function setvbuf
130 (stream : FILEs;
131 buffer : chars;
132 mode : int;
133 size : size_t) return int
135 begin
136 return C_setvbuf (stream, buffer, mode, size);
137 end setvbuf;
139 end Interfaces.C_Streams;