1------------------------------------------------------------------------------
2--                                                                          --
3--            FLORIST (FSU Implementation of POSIX.5) COMPONENTS            --
4--                                                                          --
5--      P O S I X . P E R M I S S I O N S . I M P L E M E N T A T I O N     --
6--                                                                          --
7--                                  B o d y                                 --
8--                                                                          --
9--                                                                          --
10--             Copyright (C) 1991-1994 Florida State University             --
11--                     Copyright (C) 1995-2014, AdaCore                     --
12--                                                                          --
13--  This file is a component of FLORIST, an  implementation of an  Ada API  --
14--  for the POSIX OS services, for use with  the  GNAT  Ada  compiler  and  --
15--  the FSU Gnu Ada Runtime Library (GNARL).   The  interface  is intended  --
16--  to be close to that specified in  IEEE STD  1003.5: 1990  and IEEE STD  --
17--  1003.5b: 1996.                                                          --
18--                                                                          --
19--  FLORIST is free software;  you can  redistribute  it and/or  modify it  --
20--  under terms of the  GNU  General  Public  License as  published by the  --
21--  Free Software Foundation;  either version  2, or (at  your option) any  --
22--  later version.  FLORIST is distributed  in  the hope  that  it will be  --
23--  useful, but WITHOUT ANY WARRANTY;  without  even the implied  warranty  --
24--  of MERCHANTABILITY or FITNESS FOR A PARTICULAR  PURPOSE.  See  the GNU  --
25--  General Public License for more details.  You  should have  received a  --
26--  copy of the GNU General Public License  distributed  with  GNARL;  see  --
27--  file  COPYING.  If not,  write to  the  Free  Software  Foundation, 59  --
28--  Temple Place - Suite 330, Boston, MA 02111-1307, USA.                   --
29--                                                                          --
30--                                                                          --
31--                                                                          --
32--                                                                          --
33--                                                                          --
34--                                                                          --
35--                                                                          --
36--                                                                          --
37------------------------------------------------------------------------------
38
39package body POSIX.Permissions.Implementation is
40
41   -------------------
42   --  Permissions  --
43   -------------------
44
45   function Form_C_Permission (perm : Permission_Set) return mode_t is
46      c_perm : mode_t;
47   begin
48      c_perm := 0;
49      if perm (Others_Execute) then
50         c_perm := c_perm or S_IXOTH;
51      end if;
52      if perm (Others_Write) then
53         c_perm := c_perm or S_IWOTH;
54      end if;
55      if perm (Others_Read) then
56         c_perm := c_perm or S_IROTH;
57      end if;
58      if perm (Group_Execute) then
59         c_perm := c_perm or S_IXGRP;
60      end if;
61      if perm (Group_Write) then
62         c_perm := c_perm or S_IWGRP;
63      end if;
64      if perm (Group_Read) then
65         c_perm := c_perm or S_IRGRP;
66      end if;
67      if perm (Owner_Execute) then
68         c_perm := c_perm or S_IXUSR;
69      end if;
70      if perm (Owner_Write) then
71         c_perm := c_perm or S_IWUSR;
72      end if;
73      if perm (Owner_Read) then
74         c_perm := c_perm or S_IRUSR;
75      end if;
76      if perm (Set_User_ID) then
77         c_perm := c_perm or S_ISUID;
78      end if;
79      if perm (Set_Group_ID) then
80         c_perm := c_perm or S_ISGID;
81      end if;
82      return c_perm;
83   end Form_C_Permission;
84
85   -----------------------------
86   --  form_posix_permission  --
87   -----------------------------
88
89   function Form_Ada_Permission (perm : mode_t) return Permission_Set is
90      a_perm : Permission_Set := (others => False);
91      c_perm : mode_t;
92   begin
93      c_perm := perm;
94      if (c_perm and S_IXOTH) /= 0  then
95         a_perm (Others_Execute) := True;
96      end if;
97      if (c_perm and S_IWOTH) /= 0 then
98         a_perm (Others_Write) := True;
99      end if;
100      if (c_perm and S_IROTH) /= 0 then
101         a_perm (Others_Read) := True;
102      end if;
103      if (c_perm and S_IXGRP) /= 0 then
104         a_perm (Group_Execute) := True;
105      end if;
106      if (c_perm and S_IWGRP) /= 0 then
107         a_perm (Group_Write) := True;
108      end if;
109      if (c_perm and S_IRGRP) /= 0 then
110         a_perm (Group_Read) := True;
111      end if;
112      if (c_perm and S_IXUSR) /= 0 then
113         a_perm (Owner_Execute) := True;
114      end if;
115      if (c_perm and S_IWUSR) /= 0 then
116         a_perm (Owner_Write) := True;
117      end if;
118      if (c_perm and S_IRUSR) /= 0 then
119         a_perm (Owner_Read) := True;
120      end if;
121      if (c_perm and S_ISGID) /= 0 then
122         a_perm (Set_Group_ID) := True;
123      end if;
124      if (c_perm and S_ISUID) /= 0 then
125         a_perm (Set_User_ID) := True;
126      end if;
127      return a_perm;
128   end Form_Ada_Permission;
129
130end POSIX.Permissions.Implementation;
131