summaryrefslogtreecommitdiff
path: root/lib/tmpdir.rb
blob: 8a21cdc789e3d1d547461e9df013b75d71600e16 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#
# tmpdir - retrieve temporary directory path
#
# $Id$
#

class Dir
  begin
    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 = ENV['TMPDIR']||ENV['TMP']||ENV['TEMP']||'/tmp'
    end
  end
end

if __FILE__ == $0
  puts Dir::TMPDIR
end