From e6a48c3216af984374e91cfe0e16db9d5a0314df Mon Sep 17 00:00:00 2001 From: 0x1eef <0x1eef@protonmail.com> Date: Sat, 12 Oct 2024 13:35:58 -0300 Subject: [PATCH] Add bsdcontrol_feature_find_by_name --- ext/bsdcontrol.rb/bsdcontrol.c | 9 --------- ext/bsdcontrol.rb/bsdcontrol.h | 1 - ext/bsdcontrol.rb/feature.c | 15 ++++++++++++--- ext/bsdcontrol.rb/feature.h | 5 +++++ 4 files changed, 17 insertions(+), 13 deletions(-) diff --git a/ext/bsdcontrol.rb/bsdcontrol.c b/ext/bsdcontrol.rb/bsdcontrol.c index ae24e31..a957bf5 100644 --- a/ext/bsdcontrol.rb/bsdcontrol.c +++ b/ext/bsdcontrol.rb/bsdcontrol.c @@ -40,12 +40,3 @@ bsdcontrol_open(VALUE path) } return fd; } - -hbsdctrl_feature_t * -bsdcontrol_find_feature(hbsdctrl_ctx_t *ctx, VALUE rbfeature) -{ - VALUE name; - name = rb_funcall(rbfeature, rb_intern("name"), 0); - Check_Type(name, T_STRING); - return hbsdctrl_ctx_find_feature_by_name(ctx, RSTRING_PTR(name)); -} diff --git a/ext/bsdcontrol.rb/bsdcontrol.h b/ext/bsdcontrol.rb/bsdcontrol.h index 264d19d..72633e2 100644 --- a/ext/bsdcontrol.rb/bsdcontrol.h +++ b/ext/bsdcontrol.rb/bsdcontrol.h @@ -3,4 +3,3 @@ #include int bsdcontrol_open(VALUE); -hbsdctrl_feature_t* bsdcontrol_find_feature(hbsdctrl_ctx_t*, VALUE); diff --git a/ext/bsdcontrol.rb/feature.c b/ext/bsdcontrol.rb/feature.c index 1713446..1a6f9c7 100644 --- a/ext/bsdcontrol.rb/feature.c +++ b/ext/bsdcontrol.rb/feature.c @@ -20,7 +20,7 @@ bsdcontrol_feature_status(VALUE self, VALUE path) rbcontext = rb_funcall(self, rb_intern("context"), 0); fd = bsdcontrol_open(path); ctx = bsdcontrol_context_unwrap(rbcontext); - feature = bsdcontrol_find_feature(ctx, self); + feature = bsdcontrol_feature_find_by_name(ctx, self); errno = 0; if (feature->hf_get(ctx, feature, &fd, &state) == RES_FAIL) { @@ -51,7 +51,7 @@ bsdcontrol_feature_set(VALUE self, VALUE path, VALUE rbstate) rbcontext = rb_funcall(self, rb_intern("context"), 0); fd = bsdcontrol_open(path); ctx = bsdcontrol_context_unwrap(rbcontext); - feature = bsdcontrol_find_feature(ctx, self); + feature = bsdcontrol_feature_find_by_name(ctx, self); state = NUM2INT(rbstate); errno = 0; if (feature->hf_apply(ctx, feature, &fd, &state) == RES_FAIL) @@ -80,7 +80,7 @@ bsdcontrol_feature_sysdef(VALUE self, VALUE path) rbcontext = rb_funcall(self, rb_intern("context"), 0); fd = bsdcontrol_open(path); ctx = bsdcontrol_context_unwrap(rbcontext); - feature = bsdcontrol_find_feature(ctx, self); + feature = bsdcontrol_feature_find_by_name(ctx, self); errno = 0; if (feature->hf_unapply(ctx, feature, &fd, NULL) == RES_FAIL) { @@ -94,3 +94,12 @@ bsdcontrol_feature_sysdef(VALUE self, VALUE path) return Qtrue; } } + +hbsdctrl_feature_t * +bsdcontrol_feature_find_by_name(hbsdctrl_ctx_t *ctx, VALUE rbfeature) +{ + VALUE name; + name = rb_funcall(rbfeature, rb_intern("name"), 0); + Check_Type(name, T_STRING); + return hbsdctrl_ctx_find_feature_by_name(ctx, RSTRING_PTR(name)); +} diff --git a/ext/bsdcontrol.rb/feature.h b/ext/bsdcontrol.rb/feature.h index 0f347cb..575a4d7 100644 --- a/ext/bsdcontrol.rb/feature.h +++ b/ext/bsdcontrol.rb/feature.h @@ -1,4 +1,9 @@ +#pragma once + #include +#include + VALUE bsdcontrol_feature_status(VALUE, VALUE); VALUE bsdcontrol_feature_set(VALUE,VALUE,VALUE); VALUE bsdcontrol_feature_sysdef(VALUE, VALUE); +hbsdctrl_feature_t* bsdcontrol_feature_find_by_name(hbsdctrl_ctx_t*, VALUE);