Skip to content
Browse files

better Dir.tmpdir support

git-svn-id: http://svn.macosforge.org/repository/ruby/MacRuby/trunk@4969 23306eb0-4c56-4727-a40e-e92c0eb68959
  • Loading branch information...
1 parent 0cde2c8 commit 80462d268beb501935766eee8bcf834557ac9e7c Laurent Sansonetti committed Dec 2, 2010
Showing with 14 additions and 5 deletions.
  1. +7 −0 dir.c
  2. +7 −5 lib/tmpdir.rb
View
7 dir.c
@@ -18,6 +18,7 @@
#include <sys/types.h>
#include <sys/stat.h>
+#include <sys/param.h>
#include <unistd.h>
#include <dirent.h>
#include <errno.h>
@@ -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));
}
View
12 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

0 comments on commit 80462d2

Please sign in to comment.
Something went wrong with that request. Please try again.