OSDN Git Service

* doc/install.texi (Specific, mips-sgi-irix5): Document IRIX 5
[pf3gnuchains/gcc-fork.git] / gcc / ada / tempdir.adb
index 531e3f3..b443307 100644 (file)
@@ -6,18 +6,17 @@
 --                                                                          --
 --                                 B o d y                                  --
 --                                                                          --
---          Copyright (C) 2003 Free Software Foundation, Inc.               --
+--          Copyright (C) 2003-2009, Free Software Foundation, Inc.         --
 --                                                                          --
 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
 -- terms of the  GNU General Public License as published  by the Free Soft- --
--- ware  Foundation;  either version 2,  or (at your option) any later ver- --
+-- ware  Foundation;  either version 3,  or (at your option) any later ver- --
 -- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
 -- OUT 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 GNAT;  see file COPYING.  If not, write --
--- to  the Free Software Foundation,  59 Temple Place - Suite 330,  Boston, --
--- MA 02111-1307, USA.                                                      --
+-- Public License  distributed with GNAT; see file COPYING3.  If not, go to --
+-- http://www.gnu.org/licenses for a complete copy of the license.          --
 --                                                                          --
 -- GNAT was originally developed  by the GNAT team at  New York University. --
 -- Extensive contributions were provided by Ada Core Technologies Inc.      --
 
 with GNAT.Directory_Operations; use GNAT.Directory_Operations;
 
-with Namet;  use Namet;
-with Opt;    use Opt;
-with Output; use Output;
+with Hostparm; use Hostparm;
+with Opt;      use Opt;
+with Output;   use Output;
 
 package body Tempdir is
 
    Tmpdir_Needs_To_Be_Displayed : Boolean := True;
 
-   Tmpdir   : constant String := "TMPDIR";
-   No_Dir   : aliased String  := "";
-   Temp_Dir : String_Access   := No_Dir'Access;
+   Tmpdir    : constant String := "TMPDIR";
+   Gnutmpdir : constant String := "GNUTMPDIR";
+   No_Dir    : aliased String  := "";
+   Temp_Dir  : String_Access   := No_Dir'Access;
+
+   ----------------------
+   -- Create_Temp_File --
+   ----------------------
 
    procedure Create_Temp_File
      (FD   : out File_Descriptor;
-      Name : out Name_Id)
+      Name : out Path_Name_Type)
    is
       File_Name : String_Access;
       Current_Dir : constant String := Get_Current_Dir;
@@ -90,13 +94,14 @@ package body Tempdir is
       end if;
 
       if FD = Invalid_FD then
-         Name := No_Name;
+         Write_Line ("could not create temporary file in " & Directory);
+         Name := No_Path;
 
       else
          declare
             Path_Name : constant String :=
-              Normalize_Pathname
-                (Directory & Directory_Separator & File_Name.all);
+                          Normalize_Pathname
+                            (Directory & Directory_Separator & File_Name.all);
 
          begin
             Name_Len := Path_Name'Length;
@@ -111,10 +116,28 @@ package body Tempdir is
 
 begin
    declare
-      Dir : String_Access := Getenv (Tmpdir);
+      Dir : String_Access;
 
    begin
-      if Dir'Length > 0 and then Is_Absolute_Path (Dir.all) then
+      --  On VMS, if GNUTMPDIR is defined, use it
+
+      if OpenVMS then
+         Dir := Getenv (Gnutmpdir);
+
+         --  Otherwise, if GNUTMPDIR is not defined, try TMPDIR
+
+         if Dir'Length = 0 then
+            Dir := Getenv (Tmpdir);
+         end if;
+
+      else
+         Dir := Getenv (Tmpdir);
+      end if;
+
+      if Dir'Length > 0 and then
+        Is_Absolute_Path (Dir.all) and then
+        Is_Directory (Dir.all)
+      then
          Temp_Dir := new String'(Normalize_Pathname (Dir.all));
       end if;