From 80462d268beb501935766eee8bcf834557ac9e7c Mon Sep 17 00:00:00 2001 From: Laurent Sansonetti Date: Thu, 2 Dec 2010 23:21:18 +0000 Subject: [PATCH] better Dir.tmpdir support git-svn-id: http://svn.macosforge.org/repository/ruby/MacRuby/trunk@4969 23306eb0-4c56-4727-a40e-e92c0eb68959 --- dir.c | 7 +++++++ lib/tmpdir.rb | 12 +++++++----- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/dir.c b/dir.c index 140791702..1c84e5a25 100644 --- a/dir.c +++ b/dir.c @@ -18,6 +18,7 @@ #include #include +#include #include #include #include @@ -1914,4 +1915,10 @@ Init_Dir(void) rb_file_const("FNM_DOTMATCH", INT2FIX(FNM_DOTMATCH)); rb_file_const("FNM_CASEFOLD", INT2FIX(FNM_CASEFOLD)); rb_file_const("FNM_SYSCASE", INT2FIX(FNM_SYSCASE)); + + // MacRuby extension (for tmpdir.rb). + char buf[MAXPATHLEN]; + const size_t buflen = confstr(_CS_DARWIN_USER_TEMP_DIR, buf, sizeof buf); + VALUE str = buflen > 0 ? rb_obj_freeze(rb_str_new2(buf)) : Qnil; + rb_define_const(rb_cDir, "NS_TMPDIR", rb_obj_freeze(str)); } diff --git a/lib/tmpdir.rb b/lib/tmpdir.rb index 8e0095c17..6493e1c09 100644 --- a/lib/tmpdir.rb +++ b/lib/tmpdir.rb @@ -14,9 +14,12 @@ class Dir def Dir::systmpdir @@systmpdir ||= begin - framework 'Foundation' - NSTemporaryDirectory() - end + if Dir.const_defined?(:NS_TMPDIR) + Dir::NS_TMPDIR + else + nil + end + end end ## @@ -33,8 +36,7 @@ def Dir::tmpdir break end rescue nil end - tmp ||= systmpdir - File.expand_path(tmp) + tmp ? File.expand_path(tmp) : systmpdir end end