aboutsummaryrefslogtreecommitdiffstats
path: root/lib/tmpdir.rb
diff options
context:
space:
mode:
authoreban <eban@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-07-23 16:37:35 +0000
committereban <eban@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-07-23 16:37:35 +0000
commit02f036ddbcb3409092e397b2df247bd9447e8b3f (patch)
treecc4e482833c937fb79e2ec09690f04ed2992fe7a /lib/tmpdir.rb
parent231247c010acba191b78ed2d1310c935e63ad919 (diff)
downloadruby-02f036ddbcb3409092e397b2df247bd9447e8b3f.tar.gz
* lib/tmpdir.rb (tmpdir): new method. remove TMPDIR.
use GetSystemWindowsDirectory(GetSystemDirectory), not GetTempPath. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4129 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/tmpdir.rb')
-rw-r--r--lib/tmpdir.rb38
1 files changed, 27 insertions, 11 deletions
diff --git a/lib/tmpdir.rb b/lib/tmpdir.rb
index 6fde398ed4..eaec830b08 100644
--- a/lib/tmpdir.rb
+++ b/lib/tmpdir.rb
@@ -5,22 +5,38 @@
#
class Dir
+
+ @@systmpdir = '/tmp'
+
begin
- require "Win32API"
+ require 'Win32API'
max_pathlen = 260
- t_path = ' '*(max_pathlen+1)
- t_path = t_path[0, Win32API.new('kernel32', 'GetTempPath', 'LP', 'L').call(t_path.size, t_path)]
- t_path.untaint
- TMPDIR = File.expand_path(t_path)
+ windir = ' '*(max_pathlen+1)
+ begin
+ getdir = Win32API.new('kernel32', 'GetSystemWindowsDirectory', 'PL', 'L')
+ rescue RuntimeError
+ getdir = Win32API.new('kernel32', 'GetSystemDirectory', 'PL', 'L')
+ end
+ getdir.call(windir, windir.size)
+ windir = File.expand_path(windir.rstrip.untaint)
+ temp = File.join(windir, 'temp')
+ @@systmpdir = temp if File.directory?(temp) and File.writable?(temp)
rescue LoadError
+ end
+
+ def Dir::tmpdir
+ tmp = '.'
if $SAFE > 0
- TMPDIR = '/tmp'
+ tmp = @@systmpdir
else
- TMPDIR = File.expand_path(ENV['TMPDIR']||ENV['TMP']||ENV['TEMP']||'/tmp')
+ for dir in [ENV['TMPDIR'], ENV['TMP'], ENV['TEMP'],
+ ENV['USERPROFILE'], @@systmpdir, '/tmp']
+ if dir and File.directory?(dir) and File.writable?(dir)
+ tmp = dir
+ break
+ end
+ end
end
+ File.expand_path(tmp)
end
end
-
-if __FILE__ == $0
- puts Dir::TMPDIR
-end