[macruby-changes] [4969] MacRuby/trunk

source_changes at macosforge.org source_changes at macosforge.org
Thu Dec 2 15:21:21 PST 2010


Revision: 4969
          http://trac.macosforge.org/projects/ruby/changeset/4969
Author:   lsansonetti at apple.com
Date:     2010-12-02 15:21:18 -0800 (Thu, 02 Dec 2010)
Log Message:
-----------
better Dir.tmpdir support

Modified Paths:
--------------
    MacRuby/trunk/dir.c
    MacRuby/trunk/lib/tmpdir.rb

Modified: MacRuby/trunk/dir.c
===================================================================
--- MacRuby/trunk/dir.c	2010-12-02 22:32:48 UTC (rev 4968)
+++ MacRuby/trunk/dir.c	2010-12-02 23:21:18 UTC (rev 4969)
@@ -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 @@
     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));
 }

Modified: MacRuby/trunk/lib/tmpdir.rb
===================================================================
--- MacRuby/trunk/lib/tmpdir.rb	2010-12-02 22:32:48 UTC (rev 4968)
+++ MacRuby/trunk/lib/tmpdir.rb	2010-12-02 23:21:18 UTC (rev 4969)
@@ -14,9 +14,12 @@
 
   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 @@
 	  break
 	end rescue nil
       end
-      tmp ||= systmpdir
-      File.expand_path(tmp)
+      tmp ? File.expand_path(tmp) : systmpdir
     end
   end
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20101202/152de39b/attachment.html>


More information about the macruby-changes mailing list