home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / adav313.zip / gnat-3_13p-os2-bin-20010916.zip / emx / gnatlib / i-cstrea.adb < prev    next >
Text File  |  2000-07-19  |  5KB  |  145 lines

  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. --                            $Revision: 1.5 $
  10. --                                                                          --
  11. --          Copyright (C) 1996-1999 Free Software Foundation, Inc.          --
  12. --                                                                          --
  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.                                                      --
  23. --                                                                          --
  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.                                      --
  30. --                                                                          --
  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). --
  33. --                                                                          --
  34. ------------------------------------------------------------------------------
  35.  
  36. --  This is the default version which just calls the C versions directly
  37. --  Note: the reason that we provide for specialization here is that on
  38. --  some systems, notably VMS, we may need to worry about buffering.
  39.  
  40. with Unchecked_Conversion;
  41.  
  42. package body Interfaces.C_Streams is
  43.  
  44.    ------------
  45.    -- fread --
  46.    ------------
  47.  
  48.    function fread
  49.      (buffer : voids;
  50.       size   : size_t;
  51.       count  : size_t;
  52.       stream : FILEs)
  53.       return   size_t
  54.    is
  55.       function C_fread
  56.         (buffer : voids;
  57.          size   : size_t;
  58.          count  : size_t;
  59.          stream : FILEs)
  60.          return   size_t;
  61.       pragma Import (C, C_fread, "fread");
  62.  
  63.    begin
  64.       return C_fread (buffer, size, count, stream);
  65.    end fread;
  66.  
  67.    ------------
  68.    -- fread --
  69.    ------------
  70.  
  71.    function fread
  72.      (buffer : voids;
  73.       index  : size_t;
  74.       size   : size_t;
  75.       count  : size_t;
  76.       stream : FILEs)
  77.       return   size_t
  78.    is
  79.       function C_fread
  80.         (buffer : voids;
  81.          size   : size_t;
  82.          count  : size_t;
  83.          stream : FILEs)
  84.          return   size_t;
  85.       pragma Import (C, C_fread, "fread");
  86.  
  87.       type Byte_Buffer is array (0 .. size_t'Last) of Unsigned_8;
  88.  
  89.       type Acc_Bytes is access all Byte_Buffer;
  90.  
  91.       function To_Acc_Bytes is new Unchecked_Conversion (voids, Acc_Bytes);
  92.  
  93.    begin
  94.       return C_fread
  95.         (To_Acc_Bytes (buffer) (index * size)'Address, size, count, stream);
  96.    end fread;
  97.  
  98.    ------------
  99.    -- fwrite --
  100.    ------------
  101.  
  102.    function fwrite
  103.      (buffer : voids;
  104.       size   : size_t;
  105.       count  : size_t;
  106.       stream : FILEs)
  107.       return   size_t
  108.    is
  109.       function C_fwrite
  110.         (buffer : voids;
  111.          size   : size_t;
  112.          count  : size_t;
  113.          stream : FILEs)
  114.          return   size_t;
  115.       pragma Import (C, C_fwrite, "fwrite");
  116.  
  117.    begin
  118.       return C_fwrite (buffer, size, count, stream);
  119.    end fwrite;
  120.  
  121.    -------------
  122.    -- setvbuf --
  123.    -------------
  124.  
  125.    function setvbuf
  126.      (stream : FILEs;
  127.       buffer : chars;
  128.       mode   : int;
  129.       size   : size_t)
  130.       return   int
  131.    is
  132.       function C_setvbuf
  133.         (stream : FILEs;
  134.          buffer : chars;
  135.          mode   : int;
  136.          size   : size_t)
  137.          return   int;
  138.       pragma Import (C, C_setvbuf, "setvbuf");
  139.  
  140.    begin
  141.       return C_setvbuf (stream, buffer, mode, size);
  142.    end setvbuf;
  143.  
  144. end Interfaces.C_Streams;
  145.