This file is indexed.

/usr/share/ada/adainclude/alog/alog-facilities-file_descriptor.adb is in libalog3-dev 0.5.2-3.

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
--
--  Copyright (c) 2008-2009,
--  Reto Buerki, Adrian-Ken Rueegsegger
--
--  This file is part of Alog.
--
--  Alog is free software; you can redistribute it and/or modify
--  it under the terms of the GNU Lesser General Public License as published
--  by the Free Software Foundation; either version 2.1 of the License, or
--  (at your option) any later version.
--
--  Alog 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 Lesser General Public License for more details.
--
--  You should have received a copy of the GNU Lesser General Public License
--  along with Alog; if not, write to the Free Software
--  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
--  MA  02110-1301  USA
--

with Ada.Directories;
with Ada.Exceptions;

package body Alog.Facilities.File_Descriptor is

   -------------------------------------------------------------------------

   procedure Close_Logfile
     (Facility : in out Instance;
      Remove   :        Boolean := False)
   is
      use Ada.Text_IO;
   begin
      if Facility.Log_File_Ptr /= Standard_Output
        and Is_Open (File => Facility.Log_File)
      then
         if Remove then
            --  Close and delete.
            Delete (File => Facility.Log_File);
         else
            --  Close only.
            Close (File => Facility.Log_File);
         end if;
      end if;
   end Close_Logfile;

   -------------------------------------------------------------------------

   function Get_Logfile (Facility : Instance) return Ada.Text_IO.File_Access
   is
   begin
      return Facility.Log_File_Ptr;
   end Get_Logfile;

   -------------------------------------------------------------------------

   procedure Set_Logfile
     (Facility : in out Instance;
      Path     :        String;
      Append   :        Boolean := True)
   is
   begin
      if not Ada.Directories.Exists (Name => Path) then
         Ada.Text_IO.Create (File => Facility.Log_File,
                             Mode => Ada.Text_IO.Out_File,
                             Name => Path);
      else
         declare
            File_Mode : Ada.Text_IO.File_Mode := Ada.Text_IO.Append_File;
         begin
            if not Append then
               File_Mode := Ada.Text_IO.Out_File;
            end if;

            Ada.Text_IO.Open (File => Facility.Log_File,
                              Name => Path,
                              Mode => File_Mode);
         end;
      end if;

      --  Set logfile name and pointer to newly created file.

      Facility.Log_File_Name := To_Bounded_String (Path);

      --  Unchecked_Access is needed here since we use a pointer which is
      --  defined externaly in the Text_IO library.

      Facility.Log_File_Ptr := Facility.Log_File'Unchecked_Access;

   exception
      when E : others =>
         raise Open_File_Error with "Unable to open logfile '" & Path
           & "': " & Ada.Exceptions.Exception_Message (X => E);
   end Set_Logfile;

   -------------------------------------------------------------------------

   procedure Teardown (Facility : in out Instance) is
   begin
      Facility.Close_Logfile;
   end Teardown;

   -------------------------------------------------------------------------

   procedure Write
     (Facility : Instance;
      Level    : Log_Level := Info;
      Msg      : String)
   is
      pragma Unreferenced (Level);

      use type Ada.Text_IO.File_Access;
   begin
      if Facility.Log_File_Ptr = Ada.Text_IO.Standard_Output then
         Ada.Text_IO.Put_Line (Item => Msg);
         Ada.Text_IO.Flush;
      else
         Ada.Text_IO.Put_Line (File => Facility.Log_File_Ptr.all,
                               Item => Msg);
         Ada.Text_IO.Flush (File => Facility.Log_File_Ptr.all);
      end if;
   end Write;

end Alog.Facilities.File_Descriptor;