2003-07-21 11:34:18 -04:00
|
|
|
#
|
|
|
|
# tmpdir - retrieve temporary directory path
|
|
|
|
#
|
|
|
|
# $Id$
|
|
|
|
#
|
|
|
|
|
|
|
|
class Dir
|
2003-07-23 12:37:35 -04:00
|
|
|
|
|
|
|
@@systmpdir = '/tmp'
|
|
|
|
|
2003-07-21 11:34:18 -04:00
|
|
|
begin
|
2003-07-23 12:37:35 -04:00
|
|
|
require 'Win32API'
|
2003-07-21 11:34:18 -04:00
|
|
|
max_pathlen = 260
|
2003-07-23 12:37:35 -04:00
|
|
|
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)
|
2003-07-21 11:34:18 -04:00
|
|
|
rescue LoadError
|
2003-07-23 12:37:35 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def Dir::tmpdir
|
|
|
|
tmp = '.'
|
2003-07-21 11:34:18 -04:00
|
|
|
if $SAFE > 0
|
2003-07-23 12:37:35 -04:00
|
|
|
tmp = @@systmpdir
|
2003-07-21 11:34:18 -04:00
|
|
|
else
|
2003-07-23 12:37:35 -04:00
|
|
|
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
|
2003-07-21 11:34:18 -04:00
|
|
|
end
|
2003-07-23 12:37:35 -04:00
|
|
|
File.expand_path(tmp)
|
2003-07-21 11:34:18 -04:00
|
|
|
end
|
|
|
|
end
|