ruby-changes:16262
From: naruse <ko1@a...>
Date: Tue, 8 Jun 2010 22:15:08 +0900 (JST)
Subject: [ruby-changes:16262] Ruby:r28230 (ruby_1_9_2): merge revision(s) 27667:
naruse 2010-06-08 22:14:51 +0900 (Tue, 08 Jun 2010) New Revision: 28230 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=28230 Log: merge revision(s) 27667: * ext/etc/etc.c (etc_systmpdir): moved from ext/tmpdir. * ext/etc/etc.c (etc_sysconfdir): added. * lib/rubygems/config_file.rb, lib/tmpdir.rb: use etc. Removed directories: branches/ruby_1_9_2/ext/tmpdir/ Modified files: branches/ruby_1_9_2/ChangeLog branches/ruby_1_9_2/ext/etc/etc.c branches/ruby_1_9_2/ext/etc/extconf.rb branches/ruby_1_9_2/lib/rubygems/config_file.rb branches/ruby_1_9_2/lib/tmpdir.rb branches/ruby_1_9_2/win32/win32.c Index: ruby_1_9_2/ChangeLog =================================================================== --- ruby_1_9_2/ChangeLog (revision 28229) +++ ruby_1_9_2/ChangeLog (revision 28230) @@ -1,3 +1,11 @@ +Tue Jun 8 22:14:36 2010 Nobuyoshi Nakada <nobu@r...> + + * ext/etc/etc.c (etc_systmpdir): moved from ext/tmpdir. + + * ext/etc/etc.c (etc_sysconfdir): added. + + * lib/rubygems/config_file.rb, lib/tmpdir.rb: use etc. + Tue Jun 8 06:27:09 2010 Nobuyoshi Nakada <nobu@r...> * gem_prelude.rb: load full rubygems at LoadError for activation Index: ruby_1_9_2/lib/rubygems/config_file.rb =================================================================== --- ruby_1_9_2/lib/rubygems/config_file.rb (revision 28229) +++ ruby_1_9_2/lib/rubygems/config_file.rb (revision 28230) @@ -47,15 +47,8 @@ system_config_path = begin - require 'Win32API' - - CSIDL_COMMON_APPDATA = 0x0023 - path = 0.chr * 260 - SHGetFolderPath = Win32API.new 'shell32', 'SHGetFolderPath', 'PLPLP', 'L', - :stdcall - SHGetFolderPath.call nil, CSIDL_COMMON_APPDATA, nil, 1, path - - path.strip + require 'etc.so' + Etc.sysconfdir rescue LoadError '/etc' end Index: ruby_1_9_2/lib/tmpdir.rb =================================================================== --- ruby_1_9_2/lib/tmpdir.rb (revision 28229) +++ ruby_1_9_2/lib/tmpdir.rb (revision 28230) @@ -5,13 +5,14 @@ # require 'fileutils' -if /mswin|mingw/ =~ RUBY_PLATFORM - require 'tmpdir.so' +begin + require 'etc.so' +rescue LoadError end class Dir - @@systmpdir ||= '/tmp' + @@systmpdir ||= defined?(Etc.systmpdir) ? Etc.systmpdir : '/tmp' ## # Returns the operating system's temporary file path. Index: ruby_1_9_2/win32/win32.c =================================================================== --- ruby_1_9_2/win32/win32.c (revision 28229) +++ ruby_1_9_2/win32/win32.c (revision 28230) @@ -68,6 +68,7 @@ int rb_w32_wait_events(HANDLE *events, int num, DWORD timeout); static int rb_w32_open_osfhandle(intptr_t osfhandle, int flags); static int wstati64(const WCHAR *path, struct stati64 *st); +VALUE rb_w32_conv_from_wchar(const WCHAR *wstr, rb_encoding *enc); #define RUBY_CRITICAL(expr) do { expr; } while (0) @@ -466,6 +467,16 @@ #define numberof(array) (sizeof(array) / sizeof(*array)) +VALUE +rb_w32_special_folder(int type) +{ + WCHAR path[_MAX_PATH]; + + if (!get_special_folder(type, path)) return Qnil; + regulate_path(path); + return rb_w32_conv_from_wchar(path, rb_filesystem_encoding()); +} + UINT rb_w32_system_tmpdir(WCHAR *path, UINT len) { Index: ruby_1_9_2/ext/etc/extconf.rb =================================================================== --- ruby_1_9_2/ext/etc/extconf.rb (revision 28229) +++ ruby_1_9_2/ext/etc/extconf.rb (revision 28230) @@ -4,7 +4,9 @@ a = have_func("getlogin") b = have_func("getpwent") c = have_func("getgrent") -if a or b or c +sysconfdir = RbConfig.expand(RbConfig::MAKEFILE_CONFIG["sysconfdir"].dup, "prefix"=>"") +$defs.push("-DSYSCONFDIR=#{Shellwords.escape(sysconfdir.dump)}") +if a or b or c or sysconfdir have_struct_member('struct passwd', 'pw_gecos', 'pwd.h') have_struct_member('struct passwd', 'pw_change', 'pwd.h') have_struct_member('struct passwd', 'pw_quota', 'pwd.h') Index: ruby_1_9_2/ext/etc/etc.c =================================================================== --- ruby_1_9_2/ext/etc/etc.c (revision 28229) +++ ruby_1_9_2/ext/etc/etc.c (revision 28230) @@ -8,6 +8,7 @@ ************************************************/ #include "ruby.h" +#include "ruby/encoding.h" #include <sys/types.h> #ifdef HAVE_UNISTD_H @@ -27,6 +28,13 @@ static VALUE sGroup; #endif +#ifdef _WIN32 +#include <shlobj.h> +#ifndef CSIDL_COMMON_APPDATA +#define CSIDL_COMMON_APPDATA 35 +#endif +#endif + #ifndef _WIN32 char *getenv(); #endif @@ -549,7 +557,44 @@ return Qnil; } +#define numberof(array) (sizeof(array) / sizeof(*array)) + +#ifdef _WIN32 +VALUE rb_w32_special_folder(int type); +UINT rb_w32_system_tmpdir(WCHAR *path, UINT len); +VALUE rb_w32_conv_from_wchar(const WCHAR *wstr, rb_encoding *enc); +#endif + /* + * Returns system configuration directory. + */ +static VALUE +etc_sysconfdir(VALUE obj) +{ +#ifdef _WIN32 + return rb_w32_special_folder(CSIDL_COMMON_APPDATA); +#else + return rb_filesystem_str_new_cstr(SYSCONFDIR); +#endif +} + +/* + * Returns system temporary directory. + */ +static VALUE +etc_systmpdir(void) +{ +#ifdef _WIN32 + 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 +} + +/* * The etc module provides access to information from the running OS. * * Documented by mathew <meta@p...>. @@ -575,6 +620,8 @@ rb_define_module_function(mEtc, "setgrent", etc_setgrent, 0); rb_define_module_function(mEtc, "endgrent", etc_endgrent, 0); rb_define_module_function(mEtc, "getgrent", etc_getgrent, 0); + rb_define_module_function(mEtc, "sysconfdir", etc_sysconfdir, 0); + rb_define_module_function(mEtc, "systmpdir", etc_systmpdir, 0); sPasswd = rb_struct_define("Passwd", "name", "passwd", "uid", "gid", -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/