1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* 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
This commit is contained in:
eban 2003-07-23 16:37:35 +00:00
parent 231247c010
commit 02f036ddbc
5 changed files with 39 additions and 18 deletions

View file

@ -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)
rescue LoadError
if $SAFE > 0
TMPDIR = '/tmp'
else
TMPDIR = File.expand_path(ENV['TMPDIR']||ENV['TMP']||ENV['TEMP']||'/tmp')
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
tmp = @@systmpdir
else
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