summaryrefslogtreecommitdiff
path: root/core/src/xmake/libc
diff options
context:
space:
mode:
authorruki <[email protected]>2025-11-09 23:22:44 +0800
committerruki <[email protected]>2025-11-09 23:22:44 +0800
commit831447a51da0b094e08bb047247bf269a6e6cf71 (patch)
treef345e66e3d9882cbb4d49d588c3080d88bc17cd8 /core/src/xmake/libc
parentbf2da8a3d7f04bf5ffcdce8fd4c334d5421d3494 (diff)
format more if-else
Diffstat (limited to 'core/src/xmake/libc')
-rw-r--r--core/src/xmake/libc/byteof.c12
-rw-r--r--core/src/xmake/libc/dataptr.c9
-rw-r--r--core/src/xmake/libc/free.c3
-rw-r--r--core/src/xmake/libc/malloc.c3
-rw-r--r--core/src/xmake/libc/memcpy.c3
-rw-r--r--core/src/xmake/libc/memmov.c3
-rw-r--r--core/src/xmake/libc/memset.c3
-rw-r--r--core/src/xmake/libc/setbyte.c17
-rw-r--r--core/src/xmake/libc/strndup.c12
9 files changed, 39 insertions, 26 deletions
diff --git a/core/src/xmake/libc/byteof.c b/core/src/xmake/libc/byteof.c
index dac772e9b..1d49bf815 100644
--- a/core/src/xmake/libc/byteof.c
+++ b/core/src/xmake/libc/byteof.c
@@ -38,19 +38,21 @@ tb_int_t xm_libc_byteof(lua_State *lua) {
// get data
tb_pointer_t data = tb_null;
- if (lua_isnumber(lua, 1))
+ if (lua_isnumber(lua, 1)) {
data = (tb_pointer_t)(tb_size_t)lua_tointeger(lua, 1);
- else if (lua_isstring(lua, 1))
+ } else if (lua_isstring(lua, 1)) {
data = (tb_pointer_t)luaL_checkstring(lua, 1);
- else
+ } else {
xm_libc_return_error(lua, "libc.byteof(invalid data)!");
+ }
// get offset
tb_int_t offset = 0;
- if (lua_isnumber(lua, 2))
+ if (lua_isnumber(lua, 2)) {
offset = (tb_int_t)lua_tointeger(lua, 2);
- else
+ } else {
xm_libc_return_error(lua, "libc.byteof(invalid offset)!");
+ }
lua_pushinteger(lua, ((tb_byte_t const *)data)[offset]);
return 1;
}
diff --git a/core/src/xmake/libc/dataptr.c b/core/src/xmake/libc/dataptr.c
index 363853800..881b373d2 100644
--- a/core/src/xmake/libc/dataptr.c
+++ b/core/src/xmake/libc/dataptr.c
@@ -37,14 +37,15 @@ tb_int_t xm_libc_dataptr(lua_State *lua) {
tb_assert_and_check_return_val(lua, 0);
tb_pointer_t data = tb_null;
- if (lua_isstring(lua, 1))
+ if (lua_isstring(lua, 1)) {
data = (tb_pointer_t)luaL_checkstring(lua, 1);
- else if (lua_isnumber(lua, 1))
+ } else if (lua_isnumber(lua, 1)) {
data = (tb_pointer_t)(tb_size_t)lua_tointeger(lua, 1);
- else if (xm_lua_ispointer(lua, 1))
+ } else if (xm_lua_ispointer(lua, 1)) {
data = (tb_pointer_t)xm_lua_topointer(lua, 1);
- else
+ } else {
xm_libc_return_error(lua, "libc.dataptr(invalid data)!");
+ }
lua_pushinteger(lua, (lua_Integer)(tb_long_t)data);
return 1;
}
diff --git a/core/src/xmake/libc/free.c b/core/src/xmake/libc/free.c
index 6f0d70f3d..0b686aeb5 100644
--- a/core/src/xmake/libc/free.c
+++ b/core/src/xmake/libc/free.c
@@ -38,7 +38,8 @@ tb_int_t xm_libc_free(lua_State *lua) {
// do free
tb_pointer_t data = (tb_pointer_t)(tb_size_t)luaL_checkinteger(lua, 1);
- if (data)
+ if (data) {
tb_free(data);
+ }
return 0;
}
diff --git a/core/src/xmake/libc/malloc.c b/core/src/xmake/libc/malloc.c
index faaa00e97..6bda4167d 100644
--- a/core/src/xmake/libc/malloc.c
+++ b/core/src/xmake/libc/malloc.c
@@ -39,8 +39,9 @@ tb_int_t xm_libc_malloc(lua_State *lua) {
// do malloc
tb_pointer_t data = tb_null;
tb_long_t size = (tb_long_t)luaL_checkinteger(lua, 1);
- if (size > 0)
+ if (size > 0) {
data = tb_malloc(size);
+ }
lua_pushinteger(lua, (lua_Integer)(tb_long_t)data);
return 1;
}
diff --git a/core/src/xmake/libc/memcpy.c b/core/src/xmake/libc/memcpy.c
index e0e8b1492..ce5e34312 100644
--- a/core/src/xmake/libc/memcpy.c
+++ b/core/src/xmake/libc/memcpy.c
@@ -40,7 +40,8 @@ tb_int_t xm_libc_memcpy(lua_State *lua) {
tb_pointer_t dst = (tb_pointer_t)(tb_size_t)luaL_checkinteger(lua, 1);
tb_pointer_t src = (tb_pointer_t)(tb_size_t)luaL_checkinteger(lua, 2);
tb_int_t size = (tb_int_t)lua_tointeger(lua, 3);
- if (dst && src && size > 0)
+ if (dst && src && size > 0) {
tb_memcpy(dst, src, size);
+ }
return 0;
}
diff --git a/core/src/xmake/libc/memmov.c b/core/src/xmake/libc/memmov.c
index 66120e168..1843a4301 100644
--- a/core/src/xmake/libc/memmov.c
+++ b/core/src/xmake/libc/memmov.c
@@ -40,7 +40,8 @@ tb_int_t xm_libc_memmov(lua_State *lua) {
tb_pointer_t dst = (tb_pointer_t)(tb_size_t)luaL_checkinteger(lua, 1);
tb_pointer_t src = (tb_pointer_t)(tb_size_t)luaL_checkinteger(lua, 2);
tb_int_t size = (tb_int_t)lua_tointeger(lua, 3);
- if (dst && src && size > 0)
+ if (dst && src && size > 0) {
tb_memmov(dst, src, size);
+ }
return 0;
}
diff --git a/core/src/xmake/libc/memset.c b/core/src/xmake/libc/memset.c
index 4f8864842..01b4f3f89 100644
--- a/core/src/xmake/libc/memset.c
+++ b/core/src/xmake/libc/memset.c
@@ -40,7 +40,8 @@ tb_int_t xm_libc_memset(lua_State *lua) {
tb_pointer_t data = (tb_pointer_t)(tb_size_t)luaL_checkinteger(lua, 1);
tb_char_t ch = (tb_char_t)lua_tointeger(lua, 2);
tb_int_t size = (tb_int_t)lua_tointeger(lua, 3);
- if (data && size > 0)
+ if (data && size > 0) {
tb_memset(data, ch, size);
+ }
return 0;
}
diff --git a/core/src/xmake/libc/setbyte.c b/core/src/xmake/libc/setbyte.c
index d53c30229..3bcc3fcdc 100644
--- a/core/src/xmake/libc/setbyte.c
+++ b/core/src/xmake/libc/setbyte.c
@@ -38,24 +38,27 @@ tb_int_t xm_libc_setbyte(lua_State *lua) {
// get data
tb_pointer_t data = tb_null;
- if (lua_isnumber(lua, 1))
+ if (lua_isnumber(lua, 1)) {
data = (tb_pointer_t)(tb_size_t)lua_tointeger(lua, 1);
- else if (lua_isstring(lua, 1))
+ } else if (lua_isstring(lua, 1)) {
data = (tb_pointer_t)luaL_checkstring(lua, 1);
- else
+ } else {
xm_libc_return_error(lua, "libc.setbyte(invalid data)!");
+ }
// get offset
tb_int_t offset = 0;
- if (lua_isnumber(lua, 2))
+ if (lua_isnumber(lua, 2)) {
offset = (tb_int_t)lua_tointeger(lua, 2);
- else
+ } else {
xm_libc_return_error(lua, "libc.setbyte(invalid offset)!");
+ }
// set byte
- if (lua_isnumber(lua, 3))
+ if (lua_isnumber(lua, 3)) {
((tb_byte_t *)data)[offset] = (tb_byte_t)lua_tointeger(lua, 3);
- else
+ } else {
xm_libc_return_error(lua, "libc.setbyte(invalid value)!");
+ }
return 0;
}
diff --git a/core/src/xmake/libc/strndup.c b/core/src/xmake/libc/strndup.c
index f61cebb2c..138a4907f 100644
--- a/core/src/xmake/libc/strndup.c
+++ b/core/src/xmake/libc/strndup.c
@@ -38,16 +38,18 @@ tb_int_t xm_libc_strndup(lua_State *lua) {
// do strndup
tb_char_t const *s = tb_null;
- if (lua_isnumber(lua, 1))
+ if (lua_isnumber(lua, 1)) {
s = (tb_char_t const *)(tb_size_t)lua_tointeger(lua, 1);
- else if (lua_isstring(lua, 2))
+ } else if (lua_isstring(lua, 2)) {
s = lua_tostring(lua, 2);
- else
+ } else {
xm_libc_return_error(lua, "libc.strndup(invalid args)!");
+ }
tb_int_t n = (tb_int_t)lua_tointeger(lua, 2);
- if (s && n >= 0)
+ if (s && n >= 0) {
lua_pushlstring(lua, s, n);
- else
+ } else {
lua_pushliteral(lua, "");
+ }
return 1;
}