Move bsdcontrol_* functions to bsdcontrol.c

This commit is contained in:
0x1eef 2024-10-12 02:44:48 -03:00
parent 1004595ab5
commit 376cc3a8ed
5 changed files with 37 additions and 38 deletions

View file

@ -1,6 +1,11 @@
#include <ruby.h> #include <ruby.h>
#include <libhbsdcontrol.h>
#include <fcntl.h>
#include <errno.h>
#include "context.h" #include "context.h"
#include "feature.h" #include "feature.h"
#include "bsdcontrol.h"
void void
Init_bsdcontrol(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, "ENABLED", INT2NUM(HBSDCTRL_STATE_ENABLED));
rb_define_const(rb_cFeature, "DISABLED", INT2NUM(HBSDCTRL_STATE_DISABLED)); 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));
}

View file

@ -1,7 +1,7 @@
#include <ruby.h> #include <ruby.h>
#include <libhbsdcontrol.h> #include <libhbsdcontrol.h>
#include "context.h" #include "context.h"
#include "glue.h" #include "bsdcontrol.h"
static int FLAGS = HBSDCTRL_FEATURE_STATE_FLAG_NONE; static int FLAGS = HBSDCTRL_FEATURE_STATE_FLAG_NONE;
static const char *NAMESPACE = LIBHBSDCONTROL_DEFAULT_NAMESPACE; static const char *NAMESPACE = LIBHBSDCONTROL_DEFAULT_NAMESPACE;

View file

@ -4,7 +4,7 @@
#include <errno.h> #include <errno.h>
#include "feature.h" #include "feature.h"
#include "context.h" #include "context.h"
#include "glue.h" #include "bsdcontrol.h"
/* /*
* BSD::Control::Feature#status * BSD::Control::Feature#status

View file

@ -1,36 +0,0 @@
#include <ruby.h>
#include <libhbsdcontrol.h>
#include <fcntl.h>
#include <errno.h>
#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));
}