Skip to content

Commit e5b498f

Browse files
committed
Fix sysconfdir when load-relative
When relative load paths option is enabled, the prefix is determined at the runtime. The only way to get it outside libruby is to use rbconfig.rb.
1 parent c8e0baf commit e5b498f

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

ext/etc/etc.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -691,6 +691,16 @@ etc_getgrent(VALUE obj)
691691
VALUE rb_w32_special_folder(int type);
692692
UINT rb_w32_system_tmpdir(WCHAR *path, UINT len);
693693
VALUE rb_w32_conv_from_wchar(const WCHAR *wstr, rb_encoding *enc);
694+
#elif defined(LOAD_RELATIVE)
695+
static inline VALUE
696+
rbconfig(void)
697+
{
698+
VALUE config;
699+
rb_require("rbconfig");
700+
config = rb_const_get(rb_path2class("RbConfig"), rb_intern("CONFIG"));
701+
Check_Type(config, T_HASH);
702+
return config;
703+
}
694704
#endif
695705

696706
/* call-seq:
@@ -710,6 +720,8 @@ etc_sysconfdir(VALUE obj)
710720
{
711721
#ifdef _WIN32
712722
return rb_w32_special_folder(CSIDL_COMMON_APPDATA);
723+
#elif defined(LOAD_RELATIVE)
724+
return rb_hash_aref(rbconfig(), rb_str_new_lit("sysconfdir"));
713725
#else
714726
return rb_filesystem_str_new_cstr(SYSCONFDIR);
715727
#endif

test/etc/test_etc.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,10 @@ def test_nprocessors
169169
assert_operator(1, :<=, n)
170170
end
171171

172+
def test_sysconfdir
173+
assert_operator(File, :absolute_path?, Etc.sysconfdir)
174+
end if File.method_defined?(:absolute_path?)
175+
172176
def test_ractor
173177
return unless Etc.passwd # => skip test if no platform support
174178
Etc.endpwent

0 commit comments

Comments
 (0)