Bump indent width to 4
This commit is contained in:
parent
ac2428d7c5
commit
7a43c9c1a0
5 changed files with 132 additions and 132 deletions
|
@ -1,5 +1,5 @@
|
||||||
BasedOnStyle: LLVM
|
BasedOnStyle: LLVM
|
||||||
IndentWidth: 2
|
IndentWidth: 4
|
||||||
SortIncludes: false
|
SortIncludes: false
|
||||||
UseTab: Never
|
UseTab: Never
|
||||||
BreakBeforeBraces: Allman
|
BreakBeforeBraces: Allman
|
||||||
|
|
|
@ -5,20 +5,20 @@
|
||||||
void
|
void
|
||||||
Init_bsdcontrol(void)
|
Init_bsdcontrol(void)
|
||||||
{
|
{
|
||||||
VALUE rb_mBSD = rb_const_get(rb_cObject, rb_intern("BSD")),
|
VALUE rb_mBSD = rb_const_get(rb_cObject, rb_intern("BSD")),
|
||||||
rb_mControl = rb_const_get(rb_mBSD, rb_intern("Control")),
|
rb_mControl = rb_const_get(rb_mBSD, rb_intern("Control")),
|
||||||
rb_cFeature = rb_const_get(rb_mControl, rb_intern("Feature")),
|
rb_cFeature = rb_const_get(rb_mControl, rb_intern("Feature")),
|
||||||
rb_cContext = rb_const_get(rb_mControl, rb_intern("Context"));
|
rb_cContext = rb_const_get(rb_mControl, rb_intern("Context"));
|
||||||
rb_define_alloc_func(rb_cContext, bsdcontrol_context_alloc);
|
rb_define_alloc_func(rb_cContext, bsdcontrol_context_alloc);
|
||||||
rb_define_method(
|
rb_define_method(
|
||||||
rb_cContext, "library_version", bsdcontrol_context_library_version, 0);
|
rb_cContext, "library_version", bsdcontrol_context_library_version, 0);
|
||||||
rb_define_method(rb_cContext,
|
rb_define_method(rb_cContext,
|
||||||
"available_features",
|
"available_features",
|
||||||
bsdcontrol_context_available_features,
|
bsdcontrol_context_available_features,
|
||||||
0);
|
0);
|
||||||
rb_define_method(rb_cFeature, "status", bsdcontrol_feature_status, 1);
|
rb_define_method(rb_cFeature, "status", bsdcontrol_feature_status, 1);
|
||||||
rb_define_method(rb_cFeature, "sysdef!", bsdcontrol_feature_sysdef, 1);
|
rb_define_method(rb_cFeature, "sysdef!", bsdcontrol_feature_sysdef, 1);
|
||||||
rb_define_private_method(rb_cFeature, "set!", bsdcontrol_feature_set, 2);
|
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, "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));
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,27 +10,27 @@ static void bsdcontrol_context_free(struct bsdcontrol_ctx_t *);
|
||||||
VALUE
|
VALUE
|
||||||
bsdcontrol_context_alloc(VALUE klass)
|
bsdcontrol_context_alloc(VALUE klass)
|
||||||
{
|
{
|
||||||
hbsdctrl_ctx_t *ctx;
|
hbsdctrl_ctx_t *ctx;
|
||||||
struct bsdcontrol_ctx_t *rbctx;
|
struct bsdcontrol_ctx_t *rbctx;
|
||||||
ctx = hbsdctrl_ctx_new(FLAGS, NAMESPACE);
|
ctx = hbsdctrl_ctx_new(FLAGS, NAMESPACE);
|
||||||
rbctx = calloc(1, sizeof(struct bsdcontrol_ctx_t));
|
rbctx = calloc(1, sizeof(struct bsdcontrol_ctx_t));
|
||||||
if (ctx == NULL)
|
if (ctx == NULL)
|
||||||
{
|
{
|
||||||
rb_raise(rb_eSystemCallError, "hbsdctrl_ctx_new");
|
rb_raise(rb_eSystemCallError, "hbsdctrl_ctx_new");
|
||||||
}
|
}
|
||||||
else if (rbctx == NULL)
|
else if (rbctx == NULL)
|
||||||
{
|
{
|
||||||
rb_raise(rb_eSystemCallError, "calloc");
|
rb_raise(rb_eSystemCallError, "calloc");
|
||||||
}
|
}
|
||||||
rbctx->ctx = ctx;
|
rbctx->ctx = ctx;
|
||||||
return Data_Wrap_Struct(klass, NULL, bsdcontrol_context_free, rbctx);
|
return Data_Wrap_Struct(klass, NULL, bsdcontrol_context_free, rbctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
bsdcontrol_context_free(struct bsdcontrol_ctx_t *rbctx)
|
bsdcontrol_context_free(struct bsdcontrol_ctx_t *rbctx)
|
||||||
{
|
{
|
||||||
hbsdctrl_ctx_free(&rbctx->ctx);
|
hbsdctrl_ctx_free(&rbctx->ctx);
|
||||||
free(rbctx);
|
free(rbctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -41,22 +41,22 @@ bsdcontrol_context_free(struct bsdcontrol_ctx_t *rbctx)
|
||||||
VALUE
|
VALUE
|
||||||
bsdcontrol_context_available_features(VALUE self)
|
bsdcontrol_context_available_features(VALUE self)
|
||||||
{
|
{
|
||||||
VALUE rb_mBSD = rb_const_get(rb_cObject, rb_intern("BSD")),
|
VALUE rb_mBSD = rb_const_get(rb_cObject, rb_intern("BSD")),
|
||||||
rb_mControl = rb_const_get(rb_mBSD, rb_intern("Control")),
|
rb_mControl = rb_const_get(rb_mBSD, rb_intern("Control")),
|
||||||
rb_cFeature = rb_const_get(rb_mControl, rb_intern("Feature")),
|
rb_cFeature = rb_const_get(rb_mControl, rb_intern("Feature")),
|
||||||
feature = 0, features = rb_ary_new();
|
feature = 0, features = rb_ary_new();
|
||||||
hbsdctrl_ctx_t *ctx;
|
hbsdctrl_ctx_t *ctx;
|
||||||
char **name;
|
char **name;
|
||||||
ctx = bsdcontrol_unwrap(self);
|
ctx = bsdcontrol_unwrap(self);
|
||||||
name = hbsdctrl_ctx_all_feature_names(ctx);
|
name = hbsdctrl_ctx_all_feature_names(ctx);
|
||||||
while (*name != NULL)
|
while (*name != NULL)
|
||||||
{
|
{
|
||||||
feature = rb_funcall(
|
feature = rb_funcall(
|
||||||
rb_cFeature, rb_intern("new"), 2, rb_str_new2(*name), self);
|
rb_cFeature, rb_intern("new"), 2, rb_str_new2(*name), self);
|
||||||
rb_ary_push(features, feature);
|
rb_ary_push(features, feature);
|
||||||
name++;
|
name++;
|
||||||
}
|
}
|
||||||
return features;
|
return features;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -66,7 +66,7 @@ bsdcontrol_context_available_features(VALUE self)
|
||||||
VALUE
|
VALUE
|
||||||
bsdcontrol_context_library_version(VALUE self)
|
bsdcontrol_context_library_version(VALUE self)
|
||||||
{
|
{
|
||||||
hbsdctrl_ctx_t *ctx;
|
hbsdctrl_ctx_t *ctx;
|
||||||
ctx = bsdcontrol_unwrap(self);
|
ctx = bsdcontrol_unwrap(self);
|
||||||
return ULONG2NUM(ctx->hc_version);
|
return ULONG2NUM(ctx->hc_version);
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,29 +12,29 @@
|
||||||
VALUE
|
VALUE
|
||||||
bsdcontrol_feature_status(VALUE self, VALUE path)
|
bsdcontrol_feature_status(VALUE self, VALUE path)
|
||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
VALUE rbcontext;
|
VALUE rbcontext;
|
||||||
hbsdctrl_feature_t *feature;
|
hbsdctrl_feature_t *feature;
|
||||||
hbsdctrl_feature_state_t state;
|
hbsdctrl_feature_state_t state;
|
||||||
hbsdctrl_ctx_t *ctx;
|
hbsdctrl_ctx_t *ctx;
|
||||||
rbcontext = rb_funcall(self, rb_intern("context"), 0);
|
rbcontext = rb_funcall(self, rb_intern("context"), 0);
|
||||||
fd = bsdcontrol_open(path);
|
fd = bsdcontrol_open(path);
|
||||||
ctx = bsdcontrol_unwrap(rbcontext);
|
ctx = bsdcontrol_unwrap(rbcontext);
|
||||||
feature = bsdcontrol_find_feature(ctx, self);
|
feature = bsdcontrol_find_feature(ctx, self);
|
||||||
errno = 0;
|
errno = 0;
|
||||||
if (feature->hf_get(ctx, feature, &fd, &state) == RES_FAIL)
|
if (feature->hf_get(ctx, feature, &fd, &state) == RES_FAIL)
|
||||||
{
|
{
|
||||||
close(fd);
|
close(fd);
|
||||||
errno == 0 ? rb_raise(rb_eSystemCallError, "hf_get")
|
errno == 0 ? rb_raise(rb_eSystemCallError, "hf_get")
|
||||||
: rb_syserr_fail(errno, "hf_get");
|
: rb_syserr_fail(errno, "hf_get");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
const char *str;
|
const char *str;
|
||||||
close(fd);
|
close(fd);
|
||||||
str = hbsdctrl_feature_state_to_string(&state);
|
str = hbsdctrl_feature_state_to_string(&state);
|
||||||
return ID2SYM(rb_intern(str));
|
return ID2SYM(rb_intern(str));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -43,28 +43,28 @@ bsdcontrol_feature_status(VALUE self, VALUE path)
|
||||||
VALUE
|
VALUE
|
||||||
bsdcontrol_feature_set(VALUE self, VALUE path, VALUE rbstate)
|
bsdcontrol_feature_set(VALUE self, VALUE path, VALUE rbstate)
|
||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
VALUE rbcontext;
|
VALUE rbcontext;
|
||||||
hbsdctrl_feature_t *feature;
|
hbsdctrl_feature_t *feature;
|
||||||
hbsdctrl_ctx_t *ctx;
|
hbsdctrl_ctx_t *ctx;
|
||||||
int state;
|
int state;
|
||||||
rbcontext = rb_funcall(self, rb_intern("context"), 0);
|
rbcontext = rb_funcall(self, rb_intern("context"), 0);
|
||||||
fd = bsdcontrol_open(path);
|
fd = bsdcontrol_open(path);
|
||||||
ctx = bsdcontrol_unwrap(rbcontext);
|
ctx = bsdcontrol_unwrap(rbcontext);
|
||||||
feature = bsdcontrol_find_feature(ctx, self);
|
feature = bsdcontrol_find_feature(ctx, self);
|
||||||
state = NUM2INT(rbstate);
|
state = NUM2INT(rbstate);
|
||||||
errno = 0;
|
errno = 0;
|
||||||
if (feature->hf_apply(ctx, feature, &fd, &state) == RES_FAIL)
|
if (feature->hf_apply(ctx, feature, &fd, &state) == RES_FAIL)
|
||||||
{
|
{
|
||||||
close(fd);
|
close(fd);
|
||||||
errno == 0 ? rb_raise(rb_eSystemCallError, "hf_apply")
|
errno == 0 ? rb_raise(rb_eSystemCallError, "hf_apply")
|
||||||
: rb_syserr_fail(errno, "hf_apply");
|
: rb_syserr_fail(errno, "hf_apply");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
close(fd);
|
close(fd);
|
||||||
return Qtrue;
|
return Qtrue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -73,24 +73,24 @@ bsdcontrol_feature_set(VALUE self, VALUE path, VALUE rbstate)
|
||||||
VALUE
|
VALUE
|
||||||
bsdcontrol_feature_sysdef(VALUE self, VALUE path)
|
bsdcontrol_feature_sysdef(VALUE self, VALUE path)
|
||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
VALUE rbcontext;
|
VALUE rbcontext;
|
||||||
hbsdctrl_feature_t *feature;
|
hbsdctrl_feature_t *feature;
|
||||||
hbsdctrl_ctx_t *ctx;
|
hbsdctrl_ctx_t *ctx;
|
||||||
rbcontext = rb_funcall(self, rb_intern("context"), 0);
|
rbcontext = rb_funcall(self, rb_intern("context"), 0);
|
||||||
fd = bsdcontrol_open(path);
|
fd = bsdcontrol_open(path);
|
||||||
ctx = bsdcontrol_unwrap(rbcontext);
|
ctx = bsdcontrol_unwrap(rbcontext);
|
||||||
feature = bsdcontrol_find_feature(ctx, self);
|
feature = bsdcontrol_find_feature(ctx, self);
|
||||||
errno = 0;
|
errno = 0;
|
||||||
if (feature->hf_unapply(ctx, feature, &fd, NULL) == RES_FAIL)
|
if (feature->hf_unapply(ctx, feature, &fd, NULL) == RES_FAIL)
|
||||||
{
|
{
|
||||||
close(fd);
|
close(fd);
|
||||||
errno == 0 ? rb_raise(rb_eSystemCallError, "hf_unapply")
|
errno == 0 ? rb_raise(rb_eSystemCallError, "hf_unapply")
|
||||||
: rb_syserr_fail(errno, "hf_unapply");
|
: rb_syserr_fail(errno, "hf_unapply");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
close(fd);
|
close(fd);
|
||||||
return Qtrue;
|
return Qtrue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,29 +7,29 @@
|
||||||
int
|
int
|
||||||
bsdcontrol_open(VALUE path)
|
bsdcontrol_open(VALUE path)
|
||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
Check_Type(path, T_STRING);
|
Check_Type(path, T_STRING);
|
||||||
fd = open(RSTRING_PTR(path), O_PATH);
|
fd = open(RSTRING_PTR(path), O_PATH);
|
||||||
if (fd == -1)
|
if (fd == -1)
|
||||||
{
|
{
|
||||||
rb_syserr_fail(errno, "open");
|
rb_syserr_fail(errno, "open");
|
||||||
}
|
}
|
||||||
return fd;
|
return fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
hbsdctrl_ctx_t *
|
hbsdctrl_ctx_t *
|
||||||
bsdcontrol_unwrap(VALUE rbcontext)
|
bsdcontrol_unwrap(VALUE rbcontext)
|
||||||
{
|
{
|
||||||
struct bsdcontrol_ctx_t *rbctx;
|
struct bsdcontrol_ctx_t *rbctx;
|
||||||
Data_Get_Struct(rbcontext, struct bsdcontrol_ctx_t, rbctx);
|
Data_Get_Struct(rbcontext, struct bsdcontrol_ctx_t, rbctx);
|
||||||
return rbctx->ctx;
|
return rbctx->ctx;
|
||||||
}
|
}
|
||||||
|
|
||||||
hbsdctrl_feature_t *
|
hbsdctrl_feature_t *
|
||||||
bsdcontrol_find_feature(hbsdctrl_ctx_t *ctx, VALUE rbfeature)
|
bsdcontrol_find_feature(hbsdctrl_ctx_t *ctx, VALUE rbfeature)
|
||||||
{
|
{
|
||||||
VALUE name;
|
VALUE name;
|
||||||
name = rb_funcall(rbfeature, rb_intern("name"), 0);
|
name = rb_funcall(rbfeature, rb_intern("name"), 0);
|
||||||
Check_Type(name, T_STRING);
|
Check_Type(name, T_STRING);
|
||||||
return hbsdctrl_ctx_find_feature_by_name(ctx, RSTRING_PTR(name));
|
return hbsdctrl_ctx_find_feature_by_name(ctx, RSTRING_PTR(name));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue