aboutsummaryrefslogtreecommitdiffstats
path: root/lib/tmpdir.rb
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-07-21 15:34:18 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-07-21 15:34:18 +0000
commit24162714051692617fe25fda7e88c58e25013c97 (patch)
tree619799712c383752f7cd302906684a9c0856203e /lib/tmpdir.rb
parent15c3df744f228f3d967ca624533d17f491555e93 (diff)
downloadruby-24162714051692617fe25fda7e88c58e25013c97.tar.gz
* lib/tmpdir.rb: new library to get temporary directory path,
using GetTempPath on Win32 environment. * lib/tempfile.rb: now uses tmpdir.rb. * lib/cgi/session.rb, ib/drb/unix.rb: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4109 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/tmpdir.rb')
-rw-r--r--lib/tmpdir.rb26
1 files changed, 26 insertions, 0 deletions
diff --git a/lib/tmpdir.rb b/lib/tmpdir.rb
new file mode 100644
index 0000000000..5e8dd6bf35
--- /dev/null
+++ b/lib/tmpdir.rb
@@ -0,0 +1,26 @@
+#
+# tmpdir - retrieve temporary directory path
+#
+# $Id$
+#
+
+class Dir
+ begin
+ require "Win32API"
+ max_pathlen = 260
+ t_path = ' '*(max_pathlen+1)
+ t_path[0, Win32API.new('kernel32', 'GetTempPath', 'LP', 'L').call(t_path.size, t_path)]
+ t_path.untaint
+ TMPDIR = 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