File: posix-permissions-implementation.adb

package info (click to toggle)
libflorist 2011-1
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 1,948 kB
  • sloc: ada: 11,664; ansic: 7,164; makefile: 204
file content (130 lines) | stat: -rw-r--r-- 5,554 bytes parent folder | download | duplicates (2)
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
------------------------------------------------------------------------------
--                                                                          --
--            FLORIST (FSU Implementation of POSIX.5) COMPONENTS            --
--                                                                          --
--      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     --
--                                                                          --
--                                  B o d y                                 --
--                                                                          --
--                                                                          --
--             Copyright (C) 1991-1994 Florida State University             --
--                     Copyright (C) 1995-2005 AdaCore                      --
--                                                                          --
--  This file is a component of FLORIST, an  implementation of an  Ada API  --
--  for the POSIX OS services, for use with  the  GNAT  Ada  compiler  and  --
--  the FSU Gnu Ada Runtime Library (GNARL).   The  interface  is intended  --
--  to be close to that specified in  IEEE STD  1003.5: 1990  and IEEE STD  --
--  1003.5b: 1996.                                                          --
--                                                                          --
--  FLORIST is free software;  you can  redistribute  it and/or  modify it  --
--  under terms of the  GNU  General  Public  License as  published by the  --
--  Free Software Foundation;  either version  2, or (at  your option) any  --
--  later version.  FLORIST 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  --
--  General Public License for more details.  You  should have  received a  --
--  copy of the GNU General Public License  distributed  with  GNARL;  see  --
--  file  COPYING.  If not,  write to  the  Free  Software  Foundation, 59  --
--  Temple Place - Suite 330, Boston, MA 02111-1307, USA.                   --
--                                                                          --
--                                                                          --
--                                                                          --
--                                                                          --
--                                                                          --
--                                                                          --
--                                                                          --
--                                                                          --
------------------------------------------------------------------------------

package body POSIX.Permissions.Implementation is

   -------------------
   --  Permissions  --
   -------------------

   function Form_C_Permission (perm : Permission_Set) return mode_t is
      c_perm : mode_t;
   begin
      c_perm := 0;
      if perm (Others_Execute) then
         c_perm := c_perm or S_IXOTH;
      end if;
      if perm (Others_Write) then
         c_perm := c_perm or S_IWOTH;
      end if;
      if perm (Others_Read) then
         c_perm := c_perm or S_IROTH;
      end if;
      if perm (Group_Execute) then
         c_perm := c_perm or S_IXGRP;
      end if;
      if perm (Group_Write) then
         c_perm := c_perm or S_IWGRP;
      end if;
      if perm (Group_Read) then
         c_perm := c_perm or S_IRGRP;
      end if;
      if perm (Owner_Execute) then
         c_perm := c_perm or S_IXUSR;
      end if;
      if perm (Owner_Write) then
         c_perm := c_perm or S_IWUSR;
      end if;
      if perm (Owner_Read) then
         c_perm := c_perm or S_IRUSR;
      end if;
      if perm (Set_User_ID) then
         c_perm := c_perm or S_ISUID;
      end if;
      if perm (Set_Group_ID) then
         c_perm := c_perm or S_ISGID;
      end if;
      return c_perm;
   end Form_C_Permission;

   -----------------------------
   --  form_posix_permission  --
   -----------------------------

   function Form_Ada_Permission (perm : mode_t) return Permission_Set is
      a_perm : Permission_Set := (others => False);
      c_perm : mode_t;
   begin
      c_perm := perm;
      if (c_perm and S_IXOTH) /= 0  then
         a_perm (Others_Execute) := True;
      end if;
      if (c_perm and S_IWOTH) /= 0 then
         a_perm (Others_Write) := True;
      end if;
      if (c_perm and S_IROTH) /= 0 then
         a_perm (Others_Read) := True;
      end if;
      if (c_perm and S_IXGRP) /= 0 then
         a_perm (Group_Execute) := True;
      end if;
      if (c_perm and S_IWGRP) /= 0 then
         a_perm (Group_Write) := True;
      end if;
      if (c_perm and S_IRGRP) /= 0 then
         a_perm (Group_Read) := True;
      end if;
      if (c_perm and S_IXUSR) /= 0 then
         a_perm (Owner_Execute) := True;
      end if;
      if (c_perm and S_IWUSR) /= 0 then
         a_perm (Owner_Write) := True;
      end if;
      if (c_perm and S_IRUSR) /= 0 then
         a_perm (Owner_Read) := True;
      end if;
      if (c_perm and S_ISGID) /= 0 then
         a_perm (Set_Group_ID) := True;
      end if;
      if (c_perm and S_ISUID) /= 0 then
         a_perm (Set_User_ID) := True;
      end if;
      return a_perm;
   end Form_Ada_Permission;

end POSIX.Permissions.Implementation;