summaryrefslogtreecommitdiff
path: root/core/src/xmake/libc
diff options
context:
space:
mode:
authorruki <[email protected]>2025-11-10 06:35:04 +0800
committerGitHub <[email protected]>2025-11-10 06:35:04 +0800
commit2b01e46fcf619aaecb8435b0fac975e3aff0587f (patch)
tree8f005a8dfc3272e9f027560e5e1b5881a7a8bc70 /core/src/xmake/libc
parenta1b0ec856e2c22aac84022feb05b6687912e3d6e (diff)
parent2c387895657ae13cd717d7f42f5baed5eb028a8e (diff)
Merge pull request #7008 from xmake-io/format
format code
Diffstat (limited to 'core/src/xmake/libc')
-rw-r--r--core/src/xmake/libc/byteof.c26
-rw-r--r--core/src/xmake/libc/dataptr.c19
-rw-r--r--core/src/xmake/libc/free.c13
-rw-r--r--core/src/xmake/libc/malloc.c15
-rw-r--r--core/src/xmake/libc/memcpy.c18
-rw-r--r--core/src/xmake/libc/memmov.c18
-rw-r--r--core/src/xmake/libc/memset.c16
-rw-r--r--core/src/xmake/libc/prefix.h13
-rw-r--r--core/src/xmake/libc/setbyte.c32
-rw-r--r--core/src/xmake/libc/strndup.c27
10 files changed, 94 insertions, 103 deletions
diff --git a/core/src/xmake/libc/byteof.c b/core/src/xmake/libc/byteof.c
index 6dff49100..1d49bf815 100644
--- a/core/src/xmake/libc/byteof.c
+++ b/core/src/xmake/libc/byteof.c
@@ -22,8 +22,8 @@
/* //////////////////////////////////////////////////////////////////////////////////////
* trace
*/
-#define TB_TRACE_MODULE_NAME "byteof"
-#define TB_TRACE_MODULE_DEBUG (0)
+#define TB_TRACE_MODULE_NAME "byteof"
+#define TB_TRACE_MODULE_DEBUG (0)
/* //////////////////////////////////////////////////////////////////////////////////////
* includes
@@ -33,26 +33,26 @@
/* //////////////////////////////////////////////////////////////////////////////////////
* implementation
*/
-tb_int_t xm_libc_byteof(lua_State* lua)
-{
- // check
+tb_int_t xm_libc_byteof(lua_State *lua) {
tb_assert_and_check_return_val(lua, 0);
// 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 xm_libc_return_error(lua, "libc.byteof(invalid data)!");
+ } 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 xm_libc_return_error(lua, "libc.byteof(invalid offset)!");
- lua_pushinteger(lua, ((tb_byte_t const*)data)[offset]);
+ } 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 b78b32558..881b373d2 100644
--- a/core/src/xmake/libc/dataptr.c
+++ b/core/src/xmake/libc/dataptr.c
@@ -22,8 +22,8 @@
/* //////////////////////////////////////////////////////////////////////////////////////
* trace
*/
-#define TB_TRACE_MODULE_NAME "dataptr"
-#define TB_TRACE_MODULE_DEBUG (0)
+#define TB_TRACE_MODULE_NAME "dataptr"
+#define TB_TRACE_MODULE_DEBUG (0)
/* //////////////////////////////////////////////////////////////////////////////////////
* includes
@@ -33,20 +33,19 @@
/* //////////////////////////////////////////////////////////////////////////////////////
* implementation
*/
-tb_int_t xm_libc_dataptr(lua_State* lua)
-{
- // check
+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 xm_libc_return_error(lua, "libc.dataptr(invalid data)!");
+ } 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 89dc65ed0..0b686aeb5 100644
--- a/core/src/xmake/libc/free.c
+++ b/core/src/xmake/libc/free.c
@@ -22,8 +22,8 @@
/* //////////////////////////////////////////////////////////////////////////////////////
* trace
*/
-#define TB_TRACE_MODULE_NAME "free"
-#define TB_TRACE_MODULE_DEBUG (0)
+#define TB_TRACE_MODULE_NAME "free"
+#define TB_TRACE_MODULE_DEBUG (0)
/* //////////////////////////////////////////////////////////////////////////////////////
* includes
@@ -33,14 +33,13 @@
/* //////////////////////////////////////////////////////////////////////////////////////
* implementation
*/
-tb_int_t xm_libc_free(lua_State* lua)
-{
- // check
+tb_int_t xm_libc_free(lua_State *lua) {
tb_assert_and_check_return_val(lua, 0);
// do free
tb_pointer_t data = (tb_pointer_t)(tb_size_t)luaL_checkinteger(lua, 1);
- if (data) tb_free(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 989cb6aac..6bda4167d 100644
--- a/core/src/xmake/libc/malloc.c
+++ b/core/src/xmake/libc/malloc.c
@@ -22,8 +22,8 @@
/* //////////////////////////////////////////////////////////////////////////////////////
* trace
*/
-#define TB_TRACE_MODULE_NAME "malloc"
-#define TB_TRACE_MODULE_DEBUG (0)
+#define TB_TRACE_MODULE_NAME "malloc"
+#define TB_TRACE_MODULE_DEBUG (0)
/* //////////////////////////////////////////////////////////////////////////////////////
* includes
@@ -33,16 +33,15 @@
/* //////////////////////////////////////////////////////////////////////////////////////
* implementation
*/
-tb_int_t xm_libc_malloc(lua_State* lua)
-{
- // check
+tb_int_t xm_libc_malloc(lua_State *lua) {
tb_assert_and_check_return_val(lua, 0);
// do malloc
tb_pointer_t data = tb_null;
- tb_long_t size = (tb_long_t)luaL_checkinteger(lua, 1);
- if (size > 0) data = tb_malloc(size);
+ tb_long_t size = (tb_long_t)luaL_checkinteger(lua, 1);
+ 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 d565b300e..ce5e34312 100644
--- a/core/src/xmake/libc/memcpy.c
+++ b/core/src/xmake/libc/memcpy.c
@@ -22,8 +22,8 @@
/* //////////////////////////////////////////////////////////////////////////////////////
* trace
*/
-#define TB_TRACE_MODULE_NAME "memcpy"
-#define TB_TRACE_MODULE_DEBUG (0)
+#define TB_TRACE_MODULE_NAME "memcpy"
+#define TB_TRACE_MODULE_DEBUG (0)
/* //////////////////////////////////////////////////////////////////////////////////////
* includes
@@ -33,17 +33,15 @@
/* //////////////////////////////////////////////////////////////////////////////////////
* implementation
*/
-tb_int_t xm_libc_memcpy(lua_State* lua)
-{
- // check
+tb_int_t xm_libc_memcpy(lua_State *lua) {
tb_assert_and_check_return_val(lua, 0);
// do memcpy
- 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)
+ 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) {
tb_memcpy(dst, src, size);
+ }
return 0;
}
-
diff --git a/core/src/xmake/libc/memmov.c b/core/src/xmake/libc/memmov.c
index eaa6cc8bc..1843a4301 100644
--- a/core/src/xmake/libc/memmov.c
+++ b/core/src/xmake/libc/memmov.c
@@ -22,8 +22,8 @@
/* //////////////////////////////////////////////////////////////////////////////////////
* trace
*/
-#define TB_TRACE_MODULE_NAME "memmov"
-#define TB_TRACE_MODULE_DEBUG (0)
+#define TB_TRACE_MODULE_NAME "memmov"
+#define TB_TRACE_MODULE_DEBUG (0)
/* //////////////////////////////////////////////////////////////////////////////////////
* includes
@@ -33,17 +33,15 @@
/* //////////////////////////////////////////////////////////////////////////////////////
* implementation
*/
-tb_int_t xm_libc_memmov(lua_State* lua)
-{
- // check
+tb_int_t xm_libc_memmov(lua_State *lua) {
tb_assert_and_check_return_val(lua, 0);
// do memmov
- 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)
+ 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) {
tb_memmov(dst, src, size);
+ }
return 0;
}
-
diff --git a/core/src/xmake/libc/memset.c b/core/src/xmake/libc/memset.c
index 4ac025fa2..01b4f3f89 100644
--- a/core/src/xmake/libc/memset.c
+++ b/core/src/xmake/libc/memset.c
@@ -22,8 +22,8 @@
/* //////////////////////////////////////////////////////////////////////////////////////
* trace
*/
-#define TB_TRACE_MODULE_NAME "memset"
-#define TB_TRACE_MODULE_DEBUG (0)
+#define TB_TRACE_MODULE_NAME "memset"
+#define TB_TRACE_MODULE_DEBUG (0)
/* //////////////////////////////////////////////////////////////////////////////////////
* includes
@@ -33,17 +33,15 @@
/* //////////////////////////////////////////////////////////////////////////////////////
* implementation
*/
-tb_int_t xm_libc_memset(lua_State* lua)
-{
- // check
+tb_int_t xm_libc_memset(lua_State *lua) {
tb_assert_and_check_return_val(lua, 0);
// do memset
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)
+ 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) {
tb_memset(data, ch, size);
+ }
return 0;
}
-
diff --git a/core/src/xmake/libc/prefix.h b/core/src/xmake/libc/prefix.h
index dd6dcb2ec..3bed4da3d 100644
--- a/core/src/xmake/libc/prefix.h
+++ b/core/src/xmake/libc/prefix.h
@@ -31,14 +31,11 @@
*/
// return libc error
-#define xm_libc_return_error(lua, error) \
- do \
- { \
- lua_pushnil(lua); \
- lua_pushliteral(lua, error); \
- return 2; \
+#define xm_libc_return_error(lua, error) \
+ do { \
+ lua_pushnil(lua); \
+ lua_pushliteral(lua, error); \
+ return 2; \
} while (0)
#endif
-
-
diff --git a/core/src/xmake/libc/setbyte.c b/core/src/xmake/libc/setbyte.c
index 5dd77396c..3bcc3fcdc 100644
--- a/core/src/xmake/libc/setbyte.c
+++ b/core/src/xmake/libc/setbyte.c
@@ -22,8 +22,8 @@
/* //////////////////////////////////////////////////////////////////////////////////////
* trace
*/
-#define TB_TRACE_MODULE_NAME "setbyte"
-#define TB_TRACE_MODULE_DEBUG (0)
+#define TB_TRACE_MODULE_NAME "setbyte"
+#define TB_TRACE_MODULE_DEBUG (0)
/* //////////////////////////////////////////////////////////////////////////////////////
* includes
@@ -33,30 +33,32 @@
/* //////////////////////////////////////////////////////////////////////////////////////
* implementation
*/
-tb_int_t xm_libc_setbyte(lua_State* lua)
-{
- // check
+tb_int_t xm_libc_setbyte(lua_State *lua) {
tb_assert_and_check_return_val(lua, 0);
// 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 xm_libc_return_error(lua, "libc.setbyte(invalid data)!");
+ } 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 xm_libc_return_error(lua, "libc.setbyte(invalid offset)!");
+ } else {
+ xm_libc_return_error(lua, "libc.setbyte(invalid offset)!");
+ }
// set byte
- if (lua_isnumber(lua, 3))
- ((tb_byte_t*)data)[offset] = (tb_byte_t)lua_tointeger(lua, 3);
- else xm_libc_return_error(lua, "libc.setbyte(invalid value)!");
+ if (lua_isnumber(lua, 3)) {
+ ((tb_byte_t *)data)[offset] = (tb_byte_t)lua_tointeger(lua, 3);
+ } 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 f8b32b27d..138a4907f 100644
--- a/core/src/xmake/libc/strndup.c
+++ b/core/src/xmake/libc/strndup.c
@@ -22,8 +22,8 @@
/* //////////////////////////////////////////////////////////////////////////////////////
* trace
*/
-#define TB_TRACE_MODULE_NAME "strndup"
-#define TB_TRACE_MODULE_DEBUG (0)
+#define TB_TRACE_MODULE_NAME "strndup"
+#define TB_TRACE_MODULE_DEBUG (0)
/* //////////////////////////////////////////////////////////////////////////////////////
* includes
@@ -33,22 +33,23 @@
/* //////////////////////////////////////////////////////////////////////////////////////
* implementation
*/
-tb_int_t xm_libc_strndup(lua_State* lua)
-{
- // check
+tb_int_t xm_libc_strndup(lua_State *lua) {
tb_assert_and_check_return_val(lua, 0);
// do strndup
- tb_char_t const* s = tb_null;
- if (lua_isnumber(lua, 1))
- s = (tb_char_t const*)(tb_size_t)lua_tointeger(lua, 1);
- else if (lua_isstring(lua, 2))
+ tb_char_t const *s = tb_null;
+ if (lua_isnumber(lua, 1)) {
+ s = (tb_char_t const *)(tb_size_t)lua_tointeger(lua, 1);
+ } else if (lua_isstring(lua, 2)) {
s = lua_tostring(lua, 2);
- else xm_libc_return_error(lua, "libc.strndup(invalid args)!");
+ } 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 lua_pushliteral(lua, "");
+ } else {
+ lua_pushliteral(lua, "");
+ }
return 1;
}
-