with
  Ada.IO_Exceptions,
  Ada.Strings.Unbounded,
  POSIX.IO,
  POSIX.Process_Primitives;

with
  EUP.Text_IO;

procedure Standard_Input_Redirection_2 is
   procedure Copy_3_Lines is
      Line : Ada.Strings.Unbounded.Unbounded_String;
   begin
      for I in 1 .. 3 loop
         EUP.Text_IO.Get_Line (File => EUP.Text_IO.Standard_Input,
                               Item => Line);
         EUP.Text_IO.Put_Line (File => EUP.Text_IO.Standard_Output,
                               Item => Line);
      end loop;
   end Copy_3_Lines;

   use type POSIX.IO.File_Descriptor;
   File, New_File : POSIX.IO.File_Descriptor;
begin
   Copy_3_Lines;

   File := POSIX.IO.Open (Name => "/etc/passwd",
                          Mode => POSIX.IO.Read_Only);
   POSIX.IO.Close (File => POSIX.IO.Standard_Input);
   New_File := POSIX.IO.Duplicate (File);
   if New_File /= POSIX.IO.Standard_Input then
      EUP.Text_IO.Put_Line
        (File => EUP.Text_IO.Standard_Error,
         Item => String'("Could not open data as file descriptor 0."));
      POSIX.Process_Primitives.Exit_Process (Status => 1);
   end if;

   Copy_3_Lines;
exception
   when Ada.IO_Exceptions.End_Error =>
      null;
end Standard_Input_Redirection_2;

