1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
ruby--ruby/ext/tmpdir/tmpdir.c
nobu 3694f1dda7 * 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
2010-03-16 06:20:23 +00:00

32 lines
729 B
C

#include <ruby/ruby.h>
#include <ruby/encoding.h>
#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()));
}