Bump indent width to 4

This commit is contained in:
0x1eef 2024-05-12 19:10:47 -03:00
parent ac2428d7c5
commit 7a43c9c1a0
5 changed files with 132 additions and 132 deletions

View file

@ -1,5 +1,5 @@
BasedOnStyle: LLVM
IndentWidth: 2
IndentWidth: 4
SortIncludes: false
UseTab: Never
BreakBeforeBraces: Allman

View file

@ -5,20 +5,20 @@
void
Init_bsdcontrol(void)
{
VALUE rb_mBSD = rb_const_get(rb_cObject, rb_intern("BSD")),
rb_mControl = rb_const_get(rb_mBSD, rb_intern("Control")),
rb_cFeature = rb_const_get(rb_mControl, rb_intern("Feature")),
rb_cContext = rb_const_get(rb_mControl, rb_intern("Context"));
rb_define_alloc_func(rb_cContext, bsdcontrol_context_alloc);
rb_define_method(
rb_cContext, "library_version", bsdcontrol_context_library_version, 0);
rb_define_method(rb_cContext,
"available_features",
bsdcontrol_context_available_features,
0);
rb_define_method(rb_cFeature, "status", bsdcontrol_feature_status, 1);
rb_define_method(rb_cFeature, "sysdef!", bsdcontrol_feature_sysdef, 1);
rb_define_private_method(rb_cFeature, "set!", bsdcontrol_feature_set, 2);
rb_define_const(rb_cFeature, "ENABLED", INT2NUM(HBSDCTRL_STATE_ENABLED));
rb_define_const(rb_cFeature, "DISABLED", INT2NUM(HBSDCTRL_STATE_DISABLED));
VALUE rb_mBSD = rb_const_get(rb_cObject, rb_intern("BSD")),
rb_mControl = rb_const_get(rb_mBSD, rb_intern("Control")),
rb_cFeature = rb_const_get(rb_mControl, rb_intern("Feature")),
rb_cContext = rb_const_get(rb_mControl, rb_intern("Context"));
rb_define_alloc_func(rb_cContext, bsdcontrol_context_alloc);
rb_define_method(
rb_cContext, "library_version", bsdcontrol_context_library_version, 0);
rb_define_method(rb_cContext,
"available_features",
bsdcontrol_context_available_features,
0);
rb_define_method(rb_cFeature, "status", bsdcontrol_feature_status, 1);
rb_define_method(rb_cFeature, "sysdef!", bsdcontrol_feature_sysdef, 1);
rb_define_private_method(rb_cFeature, "set!", bsdcontrol_feature_set, 2);
rb_define_const(rb_cFeature, "ENABLED", INT2NUM(HBSDCTRL_STATE_ENABLED));
rb_define_const(rb_cFeature, "DISABLED", INT2NUM(HBSDCTRL_STATE_DISABLED));
}

View file

@ -10,27 +10,27 @@ static void bsdcontrol_context_free(struct bsdcontrol_ctx_t *);
VALUE
bsdcontrol_context_alloc(VALUE klass)
{
hbsdctrl_ctx_t *ctx;
struct bsdcontrol_ctx_t *rbctx;
ctx = hbsdctrl_ctx_new(FLAGS, NAMESPACE);
rbctx = calloc(1, sizeof(struct bsdcontrol_ctx_t));
if (ctx == NULL)
{
rb_raise(rb_eSystemCallError, "hbsdctrl_ctx_new");
}
else if (rbctx == NULL)
{
rb_raise(rb_eSystemCallError, "calloc");
}
rbctx->ctx = ctx;
return Data_Wrap_Struct(klass, NULL, bsdcontrol_context_free, rbctx);
hbsdctrl_ctx_t *ctx;
struct bsdcontrol_ctx_t *rbctx;
ctx = hbsdctrl_ctx_new(FLAGS, NAMESPACE);
rbctx = calloc(1, sizeof(struct bsdcontrol_ctx_t));
if (ctx == NULL)
{
rb_raise(rb_eSystemCallError, "hbsdctrl_ctx_new");
}
else if (rbctx == NULL)
{
rb_raise(rb_eSystemCallError, "calloc");
}
rbctx->ctx = ctx;
return Data_Wrap_Struct(klass, NULL, bsdcontrol_context_free, rbctx);
}
static void
bsdcontrol_context_free(struct bsdcontrol_ctx_t *rbctx)
{
hbsdctrl_ctx_free(&rbctx->ctx);
free(rbctx);
hbsdctrl_ctx_free(&rbctx->ctx);
free(rbctx);
}
/*
@ -41,22 +41,22 @@ bsdcontrol_context_free(struct bsdcontrol_ctx_t *rbctx)
VALUE
bsdcontrol_context_available_features(VALUE self)
{
VALUE rb_mBSD = rb_const_get(rb_cObject, rb_intern("BSD")),
rb_mControl = rb_const_get(rb_mBSD, rb_intern("Control")),
rb_cFeature = rb_const_get(rb_mControl, rb_intern("Feature")),
feature = 0, features = rb_ary_new();
hbsdctrl_ctx_t *ctx;
char **name;
ctx = bsdcontrol_unwrap(self);
name = hbsdctrl_ctx_all_feature_names(ctx);
while (*name != NULL)
{
feature = rb_funcall(
rb_cFeature, rb_intern("new"), 2, rb_str_new2(*name), self);
rb_ary_push(features, feature);
name++;
}
return features;
VALUE rb_mBSD = rb_const_get(rb_cObject, rb_intern("BSD")),
rb_mControl = rb_const_get(rb_mBSD, rb_intern("Control")),
rb_cFeature = rb_const_get(rb_mControl, rb_intern("Feature")),
feature = 0, features = rb_ary_new();
hbsdctrl_ctx_t *ctx;
char **name;
ctx = bsdcontrol_unwrap(self);
name = hbsdctrl_ctx_all_feature_names(ctx);
while (*name != NULL)
{
feature = rb_funcall(
rb_cFeature, rb_intern("new"), 2, rb_str_new2(*name), self);
rb_ary_push(features, feature);
name++;
}
return features;
}
/*
@ -66,7 +66,7 @@ bsdcontrol_context_available_features(VALUE self)
VALUE
bsdcontrol_context_library_version(VALUE self)
{
hbsdctrl_ctx_t *ctx;
ctx = bsdcontrol_unwrap(self);
return ULONG2NUM(ctx->hc_version);
hbsdctrl_ctx_t *ctx;
ctx = bsdcontrol_unwrap(self);
return ULONG2NUM(ctx->hc_version);
}

View file

@ -12,29 +12,29 @@
VALUE
bsdcontrol_feature_status(VALUE self, VALUE path)
{
int fd;
VALUE rbcontext;
hbsdctrl_feature_t *feature;
hbsdctrl_feature_state_t state;
hbsdctrl_ctx_t *ctx;
rbcontext = rb_funcall(self, rb_intern("context"), 0);
fd = bsdcontrol_open(path);
ctx = bsdcontrol_unwrap(rbcontext);
feature = bsdcontrol_find_feature(ctx, self);
errno = 0;
if (feature->hf_get(ctx, feature, &fd, &state) == RES_FAIL)
{
close(fd);
errno == 0 ? rb_raise(rb_eSystemCallError, "hf_get")
: rb_syserr_fail(errno, "hf_get");
}
else
{
const char *str;
close(fd);
str = hbsdctrl_feature_state_to_string(&state);
return ID2SYM(rb_intern(str));
}
int fd;
VALUE rbcontext;
hbsdctrl_feature_t *feature;
hbsdctrl_feature_state_t state;
hbsdctrl_ctx_t *ctx;
rbcontext = rb_funcall(self, rb_intern("context"), 0);
fd = bsdcontrol_open(path);
ctx = bsdcontrol_unwrap(rbcontext);
feature = bsdcontrol_find_feature(ctx, self);
errno = 0;
if (feature->hf_get(ctx, feature, &fd, &state) == RES_FAIL)
{
close(fd);
errno == 0 ? rb_raise(rb_eSystemCallError, "hf_get")
: rb_syserr_fail(errno, "hf_get");
}
else
{
const char *str;
close(fd);
str = hbsdctrl_feature_state_to_string(&state);
return ID2SYM(rb_intern(str));
}
}
/*
@ -43,28 +43,28 @@ bsdcontrol_feature_status(VALUE self, VALUE path)
VALUE
bsdcontrol_feature_set(VALUE self, VALUE path, VALUE rbstate)
{
int fd;
VALUE rbcontext;
hbsdctrl_feature_t *feature;
hbsdctrl_ctx_t *ctx;
int state;
rbcontext = rb_funcall(self, rb_intern("context"), 0);
fd = bsdcontrol_open(path);
ctx = bsdcontrol_unwrap(rbcontext);
feature = bsdcontrol_find_feature(ctx, self);
state = NUM2INT(rbstate);
errno = 0;
if (feature->hf_apply(ctx, feature, &fd, &state) == RES_FAIL)
{
close(fd);
errno == 0 ? rb_raise(rb_eSystemCallError, "hf_apply")
: rb_syserr_fail(errno, "hf_apply");
}
else
{
close(fd);
return Qtrue;
}
int fd;
VALUE rbcontext;
hbsdctrl_feature_t *feature;
hbsdctrl_ctx_t *ctx;
int state;
rbcontext = rb_funcall(self, rb_intern("context"), 0);
fd = bsdcontrol_open(path);
ctx = bsdcontrol_unwrap(rbcontext);
feature = bsdcontrol_find_feature(ctx, self);
state = NUM2INT(rbstate);
errno = 0;
if (feature->hf_apply(ctx, feature, &fd, &state) == RES_FAIL)
{
close(fd);
errno == 0 ? rb_raise(rb_eSystemCallError, "hf_apply")
: rb_syserr_fail(errno, "hf_apply");
}
else
{
close(fd);
return Qtrue;
}
}
/*
@ -73,24 +73,24 @@ bsdcontrol_feature_set(VALUE self, VALUE path, VALUE rbstate)
VALUE
bsdcontrol_feature_sysdef(VALUE self, VALUE path)
{
int fd;
VALUE rbcontext;
hbsdctrl_feature_t *feature;
hbsdctrl_ctx_t *ctx;
rbcontext = rb_funcall(self, rb_intern("context"), 0);
fd = bsdcontrol_open(path);
ctx = bsdcontrol_unwrap(rbcontext);
feature = bsdcontrol_find_feature(ctx, self);
errno = 0;
if (feature->hf_unapply(ctx, feature, &fd, NULL) == RES_FAIL)
{
close(fd);
errno == 0 ? rb_raise(rb_eSystemCallError, "hf_unapply")
: rb_syserr_fail(errno, "hf_unapply");
}
else
{
close(fd);
return Qtrue;
}
int fd;
VALUE rbcontext;
hbsdctrl_feature_t *feature;
hbsdctrl_ctx_t *ctx;
rbcontext = rb_funcall(self, rb_intern("context"), 0);
fd = bsdcontrol_open(path);
ctx = bsdcontrol_unwrap(rbcontext);
feature = bsdcontrol_find_feature(ctx, self);
errno = 0;
if (feature->hf_unapply(ctx, feature, &fd, NULL) == RES_FAIL)
{
close(fd);
errno == 0 ? rb_raise(rb_eSystemCallError, "hf_unapply")
: rb_syserr_fail(errno, "hf_unapply");
}
else
{
close(fd);
return Qtrue;
}
}

View file

@ -7,29 +7,29 @@
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;
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)
{
struct bsdcontrol_ctx_t *rbctx;
Data_Get_Struct(rbcontext, struct bsdcontrol_ctx_t, rbctx);
return rbctx->ctx;
struct bsdcontrol_ctx_t *rbctx;
Data_Get_Struct(rbcontext, struct bsdcontrol_ctx_t, rbctx);
return rbctx->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));
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));
}