Skip to content

Commit

Permalink
better Dir.tmpdir support
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.macosforge.org/repository/ruby/MacRuby/trunk@4969 23306eb0-4c56-4727-a40e-e92c0eb68959
  • Loading branch information
lrz committed Dec 2, 2010
1 parent 0cde2c8 commit 80462d2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
7 changes: 7 additions & 0 deletions dir.c
Expand Up @@ -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>
Expand Down Expand Up @@ -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));
}
12 changes: 7 additions & 5 deletions lib/tmpdir.rb
Expand Up @@ -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

##
Expand All @@ -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

Expand Down

0 comments on commit 80462d2

Please sign in to comment.