From 376cc3a8ed1576d719e7cbbbec1aa5b79e210a79 Mon Sep 17 00:00:00 2001 From: 0x1eef <0x1eef@protonmail.com> Date: Sat, 12 Oct 2024 02:44:48 -0300 Subject: [PATCH] Move bsdcontrol_* functions to bsdcontrol.c --- ext/bsdcontrol.rb/bsdcontrol.c | 35 +++++++++++++++++++++ ext/bsdcontrol.rb/{glue.h => bsdcontrol.h} | 0 ext/bsdcontrol.rb/context.c | 2 +- ext/bsdcontrol.rb/feature.c | 2 +- ext/bsdcontrol.rb/glue.c | 36 ---------------------- 5 files changed, 37 insertions(+), 38 deletions(-) rename ext/bsdcontrol.rb/{glue.h => bsdcontrol.h} (100%) diff --git a/ext/bsdcontrol.rb/bsdcontrol.c b/ext/bsdcontrol.rb/bsdcontrol.c index dc47971..dcf03cb 100644 --- a/ext/bsdcontrol.rb/bsdcontrol.c +++ b/ext/bsdcontrol.rb/bsdcontrol.c @@ -1,6 +1,11 @@ #include +#include +#include +#include + #include "context.h" #include "feature.h" +#include "bsdcontrol.h" void Init_bsdcontrol(void) @@ -22,3 +27,33 @@ Init_bsdcontrol(void) rb_define_const(rb_cFeature, "ENABLED", INT2NUM(HBSDCTRL_STATE_ENABLED)); rb_define_const(rb_cFeature, "DISABLED", INT2NUM(HBSDCTRL_STATE_DISABLED)); } + +int +bsdcontrol_open(VALUE path) +{ + int fd; + Check_Type(path, T_STRING); + fd = open(RSTRING_PTR(path), O_PATH); + if (fd == -1) + { + rb_syserr_fail(errno, "open"); + } + return fd; +} + +hbsdctrl_ctx_t * +bsdcontrol_unwrap(VALUE rbcontext) +{ + hbsdctrl_ctx_t *ctx; + Data_Get_Struct(rbcontext, hbsdctrl_ctx_t, ctx); + return ctx; +} + +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/glue.h b/ext/bsdcontrol.rb/bsdcontrol.h similarity index 100% rename from ext/bsdcontrol.rb/glue.h rename to ext/bsdcontrol.rb/bsdcontrol.h diff --git a/ext/bsdcontrol.rb/context.c b/ext/bsdcontrol.rb/context.c index 28e1393..1ba565f 100644 --- a/ext/bsdcontrol.rb/context.c +++ b/ext/bsdcontrol.rb/context.c @@ -1,7 +1,7 @@ #include #include #include "context.h" -#include "glue.h" +#include "bsdcontrol.h" static int FLAGS = HBSDCTRL_FEATURE_STATE_FLAG_NONE; static const char *NAMESPACE = LIBHBSDCONTROL_DEFAULT_NAMESPACE; diff --git a/ext/bsdcontrol.rb/feature.c b/ext/bsdcontrol.rb/feature.c index d7d0546..5af05b3 100644 --- a/ext/bsdcontrol.rb/feature.c +++ b/ext/bsdcontrol.rb/feature.c @@ -4,7 +4,7 @@ #include #include "feature.h" #include "context.h" -#include "glue.h" +#include "bsdcontrol.h" /* * BSD::Control::Feature#status diff --git a/ext/bsdcontrol.rb/glue.c b/ext/bsdcontrol.rb/glue.c index dad9825..e69de29 100644 --- a/ext/bsdcontrol.rb/glue.c +++ b/ext/bsdcontrol.rb/glue.c @@ -1,36 +0,0 @@ -#include -#include -#include -#include -#include "glue.h" -#include "context.h" - -int -bsdcontrol_open(VALUE path) -{ - int fd; - Check_Type(path, T_STRING); - fd = open(RSTRING_PTR(path), O_PATH); - if (fd == -1) - { - rb_syserr_fail(errno, "open"); - } - return fd; -} - -hbsdctrl_ctx_t * -bsdcontrol_unwrap(VALUE rbcontext) -{ - hbsdctrl_ctx_t *ctx; - Data_Get_Struct(rbcontext, hbsdctrl_ctx_t, ctx); - return ctx; -} - -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)); -}