Skip to content

Instantly share code, notes, and snippets.

@straight-shoota
Created January 11, 2024 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save straight-shoota/14b9ebe05dafcd16dc0a77ae01d82cb4 to your computer and use it in GitHub Desktop.
Save straight-shoota/14b9ebe05dafcd16dc0a77ae01d82cb4 to your computer and use it in GitHub Desktop.
Errno location
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