[前][次][番号順一覧][スレッド一覧]

ruby-changes:15739

From: nobu <ko1@a...>
Date: Sat, 8 May 2010 12:26:19 +0900 (JST)
Subject: [ruby-changes:15739] Ruby:r27667 (trunk): * ext/etc/etc.c (etc_systmpdir): moved from ext/tmpdir.

nobu	2010-05-08 12:25:17 +0900 (Sat, 08 May 2010)

  New Revision: 27667

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=27667

  Log:
    * 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:
    trunk/ext/tmpdir/
  Modified files:
    trunk/ChangeLog
    trunk/ext/etc/etc.c
    trunk/ext/etc/extconf.rb
    trunk/lib/rubygems/config_file.rb
    trunk/lib/tmpdir.rb
    trunk/win32/win32.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 27666)
+++ ChangeLog	(revision 27667)
@@ -1,3 +1,11 @@
+Sat May  8 12:25:15 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.
+
 Sat May  8 11:07:41 2010  Nobuyoshi Nakada  <nobu@r...>
 
 	* ext/bigdecimal/bigdecimal.c (VpAlloc): ensure buf does not get
Index: lib/rubygems/config_file.rb
===================================================================
--- lib/rubygems/config_file.rb	(revision 27666)
+++ lib/rubygems/config_file.rb	(revision 27667)
@@ -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: lib/tmpdir.rb
===================================================================
--- lib/tmpdir.rb	(revision 27666)
+++ lib/tmpdir.rb	(revision 27667)
@@ -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: win32/win32.c
===================================================================
--- win32/win32.c	(revision 27666)
+++ win32/win32.c	(revision 27667)
@@ -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: ext/etc/extconf.rb
===================================================================
--- ext/etc/extconf.rb	(revision 27666)
+++ ext/etc/extconf.rb	(revision 27667)
@@ -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: ext/etc/etc.c
===================================================================
--- ext/etc/etc.c	(revision 27666)
+++ ext/etc/etc.c	(revision 27667)
@@ -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/

[前][次][番号順一覧][スレッド一覧]