adacl_5.15.1_e7c1515b/src/macos/adacl-os-low_level.ads

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
--------------------------------------------------------------- {{{1 ----------
--: Copyright (C) 2003 … 2022 Martin Krischik
------------------------------------------------------------------------------
--: This library is free software; you can redistribute it and/or modify it
--: under the terms of the GNU Library General Public License as published by
--: the Free Software Foundation; either version 2 of the License, or (at your
--: option) any later version.
--:
--: This library is distributed in the hope that it will be useful, but
--: WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
--: or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
--: License for more details.
--:
--: You should have received a copy of the GNU Library General Public License
--: along with this library; if not, write to the Free Software Foundation,
--: Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
--------------------------------------------------------------- }}}1 ----------

pragma License (Modified_Gpl);

with Ada.Unchecked_Conversion;
with GNAT.OS_Lib;
with Interfaces.C;
with System;

package AdaCL.OS.Low_Level is
   --
   --  Operating System Tools. Start extrnal Programm.
   --

   --  I/O Pipe
   type Pipe_Type is record
      Input  : GNAT.OS_Lib.File_Descriptor;
      Output : GNAT.OS_Lib.File_Descriptor;
   end record;

   --
   --  All operating systems known to AdaCL.
   --
   type Known_OS is
      (Windows,
       MacOS,
       Linux);

   --
   --  The Operating System under which this programs runs.
   --
   This_OS : constant Known_OS;

   --
   --  Error number of last C function called.
   --
   function Errno return Integer renames GNAT.OS_Lib.Errno;

   --
   --  Close a file given its file descriptor.
   --
   procedure Close (Fd : GNAT.OS_Lib.File_Descriptor);

   --
   --  Create pipe
   --
   function Pipe (Files : access Pipe_Type) return Interfaces.C.int;

   --
   --  Create pipe - GNAT Version.
   --
   function Create_Pipe (Pipe : access Pipe_Type) return Integer;

   --
   --  Create pipe - GNAT Version.
   --
   function Portable_Wait (S : System.Address) return GNAT.OS_Lib.Process_Id;

   --
   --  Cast process id to integer.
   --
   function Cast is new Ada.Unchecked_Conversion (Source => GNAT.OS_Lib.Process_Id, Target => Integer);
   --
   --  Cast process id to integer.
   --
   function Cast is new Ada.Unchecked_Conversion (Source => GNAT.OS_Lib.File_Descriptor, Target => Integer);

private

   This_OS : constant Known_OS := Linux;

   pragma Import (Convention => C, Entity => Close);

   pragma Import (Convention => C, Entity => Pipe, External_Name => "pipe");

   pragma Import (Convention => C, Entity => Portable_Wait, External_Name => "__gnat_portable_wait");

   pragma Import (Convention => C, Entity => Create_Pipe, External_Name => "__gnat_pipe");

   pragma Linker_Options ("-lgnat");

end AdaCL.OS.Low_Level;