/usr/share/ada/adainclude/florist/posix-file_locking.adb is in libflorist2014-dev 2014-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 | ------------------------------------------------------------------------------
-- --
-- FLORIST (FSU Implementation of POSIX.5) COMPONENTS --
-- --
-- P O S I X . F I L E _ L O C K I N G --
-- --
-- B o d y --
-- --
-- --
-- Copyright (C) 1996-1997 Florida State University --
-- Copyright (C) 1998-2006 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. --
-- --
-- --
-- --
-- --
-- --
-- --
-- --
-- --
------------------------------------------------------------------------------
with POSIX.C,
POSIX.Implementation,
Unchecked_Conversion;
package body POSIX.File_Locking is
use POSIX.C,
POSIX.Implementation;
function To_Process_ID is
new Unchecked_Conversion (pid_t, POSIX.Process_Identification.Process_ID);
C_Lock_Type : constant array (Lock_Kind) of short :=
(Read_Lock => F_RDLCK,
Write_Lock => F_WRLCK,
Unlock => F_UNLCK);
C_Whence : constant array (POSIX.IO.Position) of short :=
(POSIX.IO.From_Beginning => SEEK_SET,
POSIX.IO.From_End_Of_File => SEEK_END,
POSIX.IO.From_Current_Position => SEEK_CUR);
----------------
-- Get_Lock --
----------------
function fcntl
(fd : int;
cmd : int;
arg : flock_ptr) return int;
pragma Import (C, fcntl, fcntl_LINKNAME);
procedure Get_Lock
(File : POSIX.IO.File_Descriptor;
Lock : File_Lock;
Result : out File_Lock;
Process : out POSIX.Process_Identification.Process_ID) is
T : aliased struct_flock;
Res : File_Lock (False);
-- temporary is needed in case Result.Whole_File = True
begin
T.l_type := C_Lock_Type (Lock.Lock);
if Lock.Whole_File then
T.l_whence := SEEK_SET;
T.l_start := 0;
T.l_len := off_t (POSIX.IO.File_Size (File));
else
T.l_whence := C_Whence (Lock.Starting_Point);
T.l_start := off_t (Lock.Start);
T.l_len := off_t (Lock.Length);
end if;
Check (fcntl (int (File), F_GETLK, T'Unchecked_Access));
if T.l_type = F_UNLCK then
Process := POSIX.Process_Identification.Null_Process_ID;
Res.Lock := Unlock;
else
Process := To_Process_ID (T.l_pid);
if T.l_type = F_RDLCK then
Res.Lock := Read_Lock;
elsif T.l_type = F_WRLCK then
Res.Lock := Write_Lock;
else
Res.Lock := Unlock;
end if;
if T.l_whence = SEEK_SET then
Res.Starting_Point := POSIX.IO.From_Beginning;
elsif T.l_whence = SEEK_END then
Res.Starting_Point := POSIX.IO.From_End_Of_File;
else
Res.Starting_Point := POSIX.IO.From_Current_Position;
end if;
Res.Start := POSIX.IO.IO_Offset (T.l_start);
Res.Length := IO_Count (T.l_len);
end if;
Result := Res;
end Get_Lock;
----------------
-- Set_Lock --
----------------
procedure Set_Lock
(File : POSIX.IO.File_Descriptor;
Lock : File_Lock) is
T : aliased struct_flock;
begin
T.l_type := C_Lock_Type (Lock.Lock);
if Lock.Whole_File then
T.l_whence := SEEK_SET;
T.l_start := 0;
T.l_len := off_t (POSIX.IO.File_Size (File));
else
T.l_whence := C_Whence (Lock.Starting_Point);
T.l_start := off_t (Lock.Start);
T.l_len := off_t (Lock.Length);
end if;
Check (fcntl (int (File), F_SETLK, T'Unchecked_Access));
end Set_Lock;
------------------------
-- Wait_To_Set_Lock --
------------------------
procedure Wait_To_Set_Lock
(File : POSIX.IO.File_Descriptor;
Lock : File_Lock;
Masked_Signals : POSIX.Signal_Masking := POSIX.RTS_Signals) is
T : aliased struct_flock;
Result : int;
Old_Mask : aliased Signal_Mask;
begin
Mask_Signals (Masked_Signals, Old_Mask'Unchecked_Access);
T.l_type := C_Lock_Type (Lock.Lock);
if Lock.Whole_File then
T.l_whence := SEEK_SET;
T.l_start := 0;
T.l_len := off_t (POSIX.IO.File_Size (File));
else
T.l_whence := C_Whence (Lock.Starting_Point);
T.l_start := off_t (Lock.Start);
T.l_len := off_t (Lock.Length);
end if;
Result := fcntl (int (File), F_SETLKW, T'Unchecked_Access);
Check_NNeg_And_Restore_Signals
(Result, Masked_Signals, Old_Mask'Unchecked_Access);
end Wait_To_Set_Lock;
end POSIX.File_Locking;
|