adacl-os-low_level.ads

1--------------------------------------------------------------- {{{1 ----------
2--: Copyright (C) 2003 … 2022 Martin Krischik
3------------------------------------------------------------------------------
4--: This library is free software; you can redistribute it and/or modify it
5--: under the terms of the GNU Library General Public License as published by
6--: the Free Software Foundation; either version 2 of the License, or (at your
7--: option) any later version.
8--:
9--: This library is distributed in the hope that it will be useful, but
10--: WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11--: or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12--: License for more details.
13--:
14--: You should have received a copy of the GNU Library General Public License
15--: along with this library; if not, write to the Free Software Foundation,
16--: Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17--------------------------------------------------------------- }}}1 ----------
18
19pragma License (Modified_Gpl);
20
21with Ada.Unchecked_Conversion;
22with GNAT.OS_Lib;
23with Interfaces.C;
24with System;
25
26package AdaCL.OS.Low_Level is
27 --
28 -- Operating System Tools. Start extrnal Programm.
29 --
30
31 -- I/O Pipe
32 type Pipe_Type is record
33 Input : GNAT.OS_Lib.File_Descriptor;
34 Output : GNAT.OS_Lib.File_Descriptor;
35 end record;
36
37 --
38 -- All operating systems known to AdaCL.
39 --
40 type Known_OS is
41 (Windows,
42 MacOS,
43 Linux);
44
45 --
46 -- The Operating System under which this programs runs.
47 --
48 function This_OS return Known_OS with
49 Pure_Function, Inline, Post => This_OS'Result = MacOS;
50
51 --
52 -- Error number of last C function called.
53 --
54 function Errno return Integer renames GNAT.OS_Lib.Errno;
55
56 --
57 -- Close a file given its file descriptor.
58 --
59 procedure Close (Fd : GNAT.OS_Lib.File_Descriptor);
60
61 --
62 -- Create pipe
63 --
64 function Pipe (Files : access Pipe_Type) return Interfaces.C.int;
65
66 --
67 -- Create pipe - GNAT Version.
68 --
69 function Create_Pipe (Pipe : access Pipe_Type) return Integer;
70
71 --
72 -- Create pipe - GNAT Version.
73 --
74 function Portable_Wait (S : System.Address) return GNAT.OS_Lib.Process_Id;
75
76 --
77 -- Cast process id to integer.
78 --
79 function Cast is new Ada.Unchecked_Conversion (Source => GNAT.OS_Lib.Process_Id, Target => Integer);
80 --
81 -- Cast process id to integer.
82 --
83 function Cast is new Ada.Unchecked_Conversion (Source => GNAT.OS_Lib.File_Descriptor, Target => Integer);
84
85private
86
87 function This_OS return Known_OS is (MacOS);
88
89 pragma Import (Convention => C, Entity => Close);
90
91 pragma Import (Convention => C, Entity => Pipe, External_Name => "pipe");
92
93 pragma Import (Convention => C, Entity => Portable_Wait, External_Name => "__gnat_portable_wait");
94
95 pragma Import (Convention => C, Entity => Create_Pipe, External_Name => "__gnat_pipe");
96
97 pragma Linker_Options ("-lgnat");
98
99end AdaCL.OS.Low_Level;