Created
January 11, 2024 13:56
-
-
Save straight-shoota/14b9ebe05dafcd16dc0a77ae01d82cb4 to your computer and use it in GitHub Desktop.
Errno location
This file contains hidden or 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
ERNNOS = Hash(Pointer(Int32), Int32).new(0) | |
enum Errno | |
def self.pointer | |
{% if flag?(:netbsd) || flag?(:openbsd) || flag?(:android) %} | |
LibC.__errno | |
{% elsif flag?(:linux) || flag?(:dragonfly) %} | |
LibC.__errno_location | |
{% elsif flag?(:wasi) %} | |
raise NotImplementedError.new("Errno.pointer") | |
{% elsif flag?(:darwin) || flag?(:freebsd) %} | |
LibC.__error | |
{% elsif flag?(:win32) %} | |
raise NotImplementedError.new("Errno.pointer") | |
{% end %} | |
end | |
end | |
def print_errno_info(name) | |
puts "#{name}: #{Thread.current} errno at #{Errno.pointer}" | |
ERNNOS[Errno.pointer] += 1 | |
end | |
count = ARGV[0]?.try(&.to_i) || 10 | |
count.times do |i| | |
Thread.new do | |
print_errno_info(i) | |
end | |
end | |
print_errno_info("main") | |
print "Distribution: " | |
ERNNOS.values.join(STDOUT, ", ") | |
puts |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment