-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
87 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
require "c/sysinfoapi" | ||
|
||
module Crystal::System | ||
def self.cpu_count | ||
LibC.GetNativeSystemInfo(out system_info) | ||
system_info.dwNumberOfProcessors | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
require "c/sysinfoapi" | ||
|
||
module Crystal::System | ||
def self.hostname | ||
retry_wstr_buffer do |buffer, small_buf| | ||
name_size = LibC::DWORD.new(buffer.size) | ||
if LibC.GetComputerNameExW(LibC::COMPUTER_NAME_FORMAT::ComputerNameDnsHostname, buffer, pointerof(name_size)) != 0 | ||
break String.from_utf16(buffer[0, name_size]) | ||
elsif small_buf && name_size > 0 | ||
next name_size | ||
else | ||
raise WinError.new("GetComputerNameExW") | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
require "c/winnt" | ||
require "c/win_def" | ||
require "c/int_safe" | ||
|
||
lib LibC | ||
fun GetNativeSystemInfo(system_info : SYSTEM_INFO*) | ||
|
||
struct PROCESSOR_INFO | ||
wProcessorArchitecture : WORD | ||
wReserved : WORD | ||
end | ||
|
||
union OEM_PROCESSOR_INFO | ||
dwOemId : DWORD | ||
processorInfo : PROCESSOR_INFO | ||
end | ||
|
||
struct SYSTEM_INFO | ||
oemProcessorInfo : OEM_PROCESSOR_INFO | ||
dwPageSize : DWORD | ||
lpMinimumApplicationAddress : Void* | ||
lpMaximumApplicationAddress : Void* | ||
dwActiveProcessorMask : DWORD* | ||
dwNumberOfProcessors : DWORD | ||
dwProcessorType : DWORD | ||
dwAllocationGranularity : DWORD | ||
wProcessorLevel : WORD | ||
wProcessorRevision : WORD | ||
end | ||
|
||
fun GetComputerNameExW(computer_name_format : COMPUTER_NAME_FORMAT, | ||
machine_name : LPWSTR, | ||
machine_name_size : DWORD*) : BOOLEAN | ||
|
||
enum COMPUTER_NAME_FORMAT | ||
ComputerNameNetBIOS | ||
ComputerNameDnsHostname | ||
ComputerNameDnsDomain | ||
ComputerNameDnsFullyQualified | ||
ComputerNamePhysicalNetBIOS | ||
ComputerNamePhysicalDnsHostname | ||
ComputerNamePhysicalDomain | ||
ComputerNamePhysicalDnsFullyQualified | ||
end | ||
end |