From 3694f1dda70923b2acc66af6553c422ba87daddd Mon Sep 17 00:00:00 2001 From: nobu Date: Tue, 16 Mar 2010 06:20:23 +0000 Subject: * ext/tmpdir: split from lib/tmpdir.rb. * win32/win32.c (rb_w32_system_tmpdir): extracted from init_env. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@26952 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ext/tmpdir/extconf.rb | 6 ++++++ ext/tmpdir/tmpdir.c | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 ext/tmpdir/extconf.rb create mode 100644 ext/tmpdir/tmpdir.c (limited to 'ext/tmpdir') diff --git a/ext/tmpdir/extconf.rb b/ext/tmpdir/extconf.rb new file mode 100644 index 0000000000..a283f851b0 --- /dev/null +++ b/ext/tmpdir/extconf.rb @@ -0,0 +1,6 @@ +case +when have_func("rb_w32_system_tmpdir") + ok = true # win32 +else +end +create_makefile("tmpdir") if ok diff --git a/ext/tmpdir/tmpdir.c b/ext/tmpdir/tmpdir.c new file mode 100644 index 0000000000..f046713b63 --- /dev/null +++ b/ext/tmpdir/tmpdir.c @@ -0,0 +1,32 @@ +#include +#include + +#define numberof(array) (sizeof(array) / sizeof(*array)) + +#ifdef HAVE_RB_W32_SYSTEM_TMPDIR +UINT rb_w32_system_tmpdir(WCHAR *path, UINT len); +VALUE rb_w32_conv_from_wchar(const WCHAR *wstr, rb_encoding *enc); +#endif + +static VALUE +system_tmpdir(void) +{ +#ifdef HAVE_RB_W32_SYSTEM_TMPDIR + WCHAR path[_MAX_PATH]; + UINT len = rb_w32_system_tmpdir(path, numberof(path)); + if (!len) return Qnil; + return rb_w32_conv_from_wchar(path, rb_filesystem_encoding()); +#else + return rb_filesystem_str_new_cstr("/tmp"); +#endif +} + +/* + * sets Dir.@@systmpdir. + */ +void +Init_tmpdir(void) +{ + rb_cvar_set(rb_cDir, rb_intern_const("@@systmpdir"), + rb_obj_freeze(system_tmpdir())); +} -- cgit v1.2.3