diff options
author | Jo-Philipp Wich <jo@mein.io> | 2020-09-10 16:34:12 +0200 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2020-09-10 16:35:13 +0200 |
commit | 39164c57d893b02f9a253c661abc2459bcd57e5c (patch) | |
tree | 7df7bb35122bc692818feb883726e5910b892101 /lib | |
parent | d33d86fae9b72b352a335488e2e1401e3b0c66a1 (diff) |
treewide: eliminate unused function arguments
Also introduce convenience macro for registering function arrays in modules.
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/fs.c | 65 | ||||
-rw-r--r-- | lib/ubus.c | 14 |
2 files changed, 35 insertions, 44 deletions
@@ -221,7 +221,7 @@ ut_fs_popen(struct ut_state *s, uint32_t off, struct json_object *args) err_return(ENOMEM); } - return ops->set_type(s, fo, proc_proto, "fs.proc", fp); + return ops->set_type(fo, proc_proto, "fs.proc", fp); } @@ -328,7 +328,7 @@ ut_fs_open(struct ut_state *s, uint32_t off, struct json_object *args) err_return(ENOMEM); } - return ops->set_type(s, fo, file_proto, "fs.file", fp); + return ops->set_type(fo, file_proto, "fs.file", fp); } @@ -423,7 +423,7 @@ ut_fs_opendir(struct ut_state *s, uint32_t off, struct json_object *args) err_return(ENOMEM); } - return ops->set_type(s, diro, dir_proto, "fs.dir", dp); + return ops->set_type(diro, dir_proto, "fs.dir", dp); } static struct json_object * @@ -622,8 +622,28 @@ ut_fs_unlink(struct ut_state *s, uint32_t off, struct json_object *args) return json_object_new_boolean(true); } +static const struct { const char *name; ut_c_fn *func; } proc_fns[] = { + { "read", ut_fs_pread }, + { "write", ut_fs_pwrite }, + { "close", ut_fs_pclose }, +}; + +static const struct { const char *name; ut_c_fn *func; } file_fns[] = { + { "read", ut_fs_read }, + { "write", ut_fs_write }, + { "seek", ut_fs_seek }, + { "tell", ut_fs_tell }, + { "close", ut_fs_close }, +}; -static const struct { const char *name; ut_c_fn *func; } functions[] = { +static const struct { const char *name; ut_c_fn *func; } dir_fns[] = { + { "read", ut_fs_readdir }, + { "seek", ut_fs_seekdir }, + { "tell", ut_fs_telldir }, + { "close", ut_fs_closedir }, +}; + +static const struct { const char *name; ut_c_fn *func; } global_fns[] = { { "error", ut_fs_error }, { "open", ut_fs_open }, { "opendir", ut_fs_opendir }, @@ -652,40 +672,17 @@ static void close_dir(void *ud) { void ut_module_init(const struct ut_ops *ut, struct ut_state *s, struct json_object *scope) { - int i; - ops = ut; ops->register_type("fs.proc", close_proc); ops->register_type("fs.file", close_file); ops->register_type("fs.dir", close_dir); - for (i = 0; i < ARRAY_SIZE(functions); i++) - ops->register_function(s, scope, functions[i].name, functions[i].func); - - proc_proto = ops->new_object(s, NULL); + proc_proto = ops->new_object(NULL); + file_proto = ops->new_object(NULL); + dir_proto = ops->new_object(NULL); - if (proc_proto) { - ops->register_function(s, proc_proto, "read", ut_fs_pread); - ops->register_function(s, proc_proto, "write", ut_fs_pwrite); - ops->register_function(s, proc_proto, "close", ut_fs_pclose); - } - - file_proto = ops->new_object(s, NULL); - - if (file_proto) { - ops->register_function(s, file_proto, "read", ut_fs_read); - ops->register_function(s, file_proto, "write", ut_fs_write); - ops->register_function(s, file_proto, "seek", ut_fs_seek); - ops->register_function(s, file_proto, "tell", ut_fs_tell); - ops->register_function(s, file_proto, "close", ut_fs_close); - } - - dir_proto = ops->new_object(s, NULL); - - if (dir_proto) { - ops->register_function(s, dir_proto, "read", ut_fs_readdir); - ops->register_function(s, dir_proto, "seek", ut_fs_seekdir); - ops->register_function(s, dir_proto, "tell", ut_fs_telldir); - ops->register_function(s, dir_proto, "close", ut_fs_closedir); - } + register_functions(ops, global_fns, scope); + register_functions(ops, proc_fns, proc_proto); + register_functions(ops, file_fns, file_proto); + register_functions(ops, dir_fns, dir_proto); } @@ -171,7 +171,7 @@ ut_ubus_connect(struct ut_state *s, uint32_t off, struct json_object *args) ubus_add_uloop(c->ctx); - return ops->set_type(s, co, conn_proto, "ubus.connection", c); + return ops->set_type(co, conn_proto, "ubus.connection", c); } static void @@ -317,17 +317,11 @@ static void close_connection(void *ud) { void ut_module_init(const struct ut_ops *ut, struct ut_state *s, struct json_object *scope) { - int i; - ops = ut; ops->register_type("ubus.connection", close_connection); - for (i = 0; i < ARRAY_SIZE(global_fns); i++) - ops->register_function(s, scope, global_fns[i].name, global_fns[i].func); - - conn_proto = ops->new_object(s, NULL); + conn_proto = ops->new_object(NULL); - if (conn_proto) - for (i = 0; i < ARRAY_SIZE(global_fns); i++) - ops->register_function(s, conn_proto, conn_fns[i].name, conn_fns[i].func); + register_functions(ops, global_fns, scope); + register_functions(ops, conn_fns, conn_proto); } |