From 2db227b0c34ddb669b78a32f8c794f76a6e5a840 Mon Sep 17 00:00:00 2001 From: 0x1eef <0x1eef@protonmail.com> Date: Fri, 1 Mar 2024 01:28:54 -0300 Subject: [PATCH] Add BSD::Control.library_version --- ext/hbsdctl.rb/hbsdctl.c | 9 +++++++++ lib/bsd/control.rb | 7 +++++++ lib/bsd/control/feature.rb | 1 - 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/ext/hbsdctl.rb/hbsdctl.c b/ext/hbsdctl.rb/hbsdctl.c index 743cb26..1f7f149 100644 --- a/ext/hbsdctl.rb/hbsdctl.c +++ b/ext/hbsdctl.rb/hbsdctl.c @@ -26,6 +26,14 @@ ffi_available_features(VALUE self) return features; } +static VALUE +ffi_library_version(VALUE self) +{ + const char *ver; + ver = hbsdcontrol_get_version(); + return rb_str_new2(ver); +} + static VALUE feature_set(VALUE self, VALUE path, VALUE state) { @@ -65,5 +73,6 @@ Init_hbsdctl(void) rb_define_const(rb_mControl, "Disable", 0); rb_define_const(rb_mControl, "Enable", 1); rb_define_singleton_method(rb_mFFI, "available_features", ffi_available_features, 0); + rb_define_singleton_method(rb_mFFI, "library_version", ffi_library_version, 0); rb_define_method(rb_cFeature, "set!", feature_set, 2); } diff --git a/lib/bsd/control.rb b/lib/bsd/control.rb index 287d33a..c8f148e 100644 --- a/lib/bsd/control.rb +++ b/lib/bsd/control.rb @@ -2,6 +2,13 @@ module BSD::Control require_relative "control/feature" Error = Class.new(RuntimeError) + ## + # @return [String] + # Returns the version of libhbsdcontrol. + def self.library_version + FFI.library_version + end + ## # @return [Array] def self.available_features diff --git a/lib/bsd/control/feature.rb b/lib/bsd/control/feature.rb index 50d7e75..d3b576e 100644 --- a/lib/bsd/control/feature.rb +++ b/lib/bsd/control/feature.rb @@ -124,6 +124,5 @@ module BSD::Control end # @endgroup - private :set! end end