From de95f557b00e3793d1befbc1dd7a763b16c91a31 Mon Sep 17 00:00:00 2001 From: Charles Oliver Nutter Date: Tue, 10 Dec 2024 15:48:18 -0600 Subject: [PATCH] Check for Windows in JRuby-compatible way --- lib/resolv.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/resolv.rb b/lib/resolv.rb index 232a339..279d05d 100644 --- a/lib/resolv.rb +++ b/lib/resolv.rb @@ -160,11 +160,14 @@ class ResolvError < StandardError; end class ResolvTimeout < Timeout::Error; end + WINDOWS = /mswin|cygwin|mingw|bccwin/ =~ RUBY_PLATFORM || ::RbConfig::CONFIG['host_os'] =~ /mswin/ + private_constant :WINDOWS + ## # Resolv::Hosts is a hostname resolver that uses the system hosts file. class Hosts - if /mswin|mingw|cygwin/ =~ RUBY_PLATFORM and + if WINDOWS begin require 'win32/resolv' DefaultFileName = Win32::Resolv.get_hosts_path || IO::NULL @@ -994,7 +997,7 @@ def Config.default_config_hash(filename="/etc/resolv.conf") if File.exist? filename config_hash = Config.parse_resolv_conf(filename) else - if /mswin|cygwin|mingw|bccwin/ =~ RUBY_PLATFORM + if WINDOWS require 'win32/resolv' search, nameserver = Win32::Resolv.get_resolv_info config_hash = {}