PR8383516.diff   [plain text]


--- dir.c.old	2010-12-02 15:57:24.000000000 -0800
+++ dir.c	2010-12-02 15:59:19.000000000 -0800
@@ -16,6 +16,7 @@
 
 #include <sys/types.h>
 #include <sys/stat.h>
+#include <sys/param.h>
 
 #ifdef HAVE_UNISTD_H
 #include <unistd.h>
@@ -2002,4 +2003,9 @@
     rb_file_const("FNM_DOTMATCH", INT2FIX(FNM_DOTMATCH));
     rb_file_const("FNM_CASEFOLD", INT2FIX(FNM_CASEFOLD));
     rb_file_const("FNM_SYSCASE", INT2FIX(FNM_SYSCASE));
+
+    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", str);
 }
--- lib/tmpdir.rb.old	2010-12-02 15:57:28.000000000 -0800
+++ lib/tmpdir.rb	2010-12-02 15:58:18.000000000 -0800
@@ -8,7 +8,7 @@
 
 class Dir
 
-  @@systmpdir = '/tmp'
+  @@systmpdir = Dir.const_defined?(:NS_TMPDIR) ? Dir::NS_TMPDIR : '/tmp'
 
   begin
     require 'Win32API'