diff options
| author | ruki <[email protected]> | 2025-11-10 23:20:11 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2025-11-10 23:20:11 +0800 |
| commit | ef701a4dce8b7d9a663e084d1fc0b243ddae9397 (patch) | |
| tree | 45fd20851dd3480bd042dd14af77286c4289d190 /core/src/xmake/os | |
| parent | 6db4c62a474e380071625fa5cb7743972a562940 (diff) | |
format core code again
Diffstat (limited to 'core/src/xmake/os')
| -rw-r--r-- | core/src/xmake/os/args.c | 12 | ||||
| -rw-r--r-- | core/src/xmake/os/argv.c | 12 | ||||
| -rw-r--r-- | core/src/xmake/os/cpuinfo.c | 50 | ||||
| -rw-r--r-- | core/src/xmake/os/find.c | 4 | ||||
| -rw-r--r-- | core/src/xmake/os/getenvs.c | 10 | ||||
| -rw-r--r-- | core/src/xmake/os/meminfo.c | 14 | ||||
| -rw-r--r-- | core/src/xmake/os/readlink.c | 2 | ||||
| -rw-r--r-- | core/src/xmake/os/setenv.c | 6 | ||||
| -rw-r--r-- | core/src/xmake/os/syserror.c | 2 |
9 files changed, 56 insertions, 56 deletions
diff --git a/core/src/xmake/os/args.c b/core/src/xmake/os/args.c index b48445c89..02c576aef 100644 --- a/core/src/xmake/os/args.c +++ b/core/src/xmake/os/args.c @@ -38,9 +38,9 @@ static tb_void_t tb_os_args_append( tb_assert_and_check_return(size < TB_PATH_MAXN); // need wrap quote? - tb_char_t ch; - tb_char_t const *p = cstr; - tb_bool_t wrap_quote = tb_false; + tb_char_t ch; + tb_char_t const *p = cstr; + tb_bool_t wrap_quote = tb_false; if (!nowrap) { while ((ch = *p)) { if (ch == ' ') { @@ -119,14 +119,14 @@ tb_int_t xm_os_args(lua_State *lua) { if (lua_istable(lua, -1)) { // is path instance? lua_pushstring(lua, "_STR"); lua_gettable(lua, -2); - size_t size = 0; + size_t size = 0; tb_char_t const *cstr = luaL_checklstring(lua, -1, &size); if (cstr && size) { tb_os_args_append(&result, cstr, size, escape, nowrap); } lua_pop(lua, 1); } else { - size_t size = 0; + size_t size = 0; tb_char_t const *cstr = luaL_checklstring(lua, -1, &size); if (cstr && size) { tb_os_args_append(&result, cstr, size, escape, nowrap); @@ -135,7 +135,7 @@ tb_int_t xm_os_args(lua_State *lua) { lua_pop(lua, 1); } } else { - size_t size = 0; + size_t size = 0; tb_char_t const *cstr = luaL_checklstring(lua, 1, &size); if (cstr && size) { tb_os_args_append(&result, cstr, size, escape, nowrap); diff --git a/core/src/xmake/os/argv.c b/core/src/xmake/os/argv.c index 12b1f88ec..09a9d27ec 100644 --- a/core/src/xmake/os/argv.c +++ b/core/src/xmake/os/argv.c @@ -61,12 +61,12 @@ tb_int_t xm_os_argv(lua_State *lua) { } // parse command to the arguments - tb_int_t i = 1; - tb_int_t skip = 0; - tb_int_t escape = 0; - tb_char_t quote = 0; - tb_char_t ch = 0; - tb_char_t const *p = args; + tb_int_t i = 1; + tb_int_t skip = 0; + tb_int_t escape = 0; + tb_char_t quote = 0; + tb_char_t ch = 0; + tb_char_t const *p = args; while ((ch = *p)) { // no escape now? if (!escape) { diff --git a/core/src/xmake/os/cpuinfo.c b/core/src/xmake/os/cpuinfo.c index 7be9172cc..47542a4b4 100644 --- a/core/src/xmake/os/cpuinfo.c +++ b/core/src/xmake/os/cpuinfo.c @@ -65,15 +65,15 @@ static tb_uint64_t xm_os_cpuinfo_subtract_times(FILETIME const *one, FILETIME co static tb_float_t xm_os_cpuinfo_usagerate() { #if defined(TB_CONFIG_OS_MACOSX) - tb_float_t usagerate = 0; - natural_t cpu_count = 0; + tb_float_t usagerate = 0; + natural_t cpu_count = 0; processor_info_array_t cpuinfo; mach_msg_type_number_t cpuinfo_count; - static tb_hong_t s_time = 0; + static tb_hong_t s_time = 0; if (tb_mclock() - s_time > 1000 && host_processor_info(mach_host_self(), PROCESSOR_CPU_LOAD_INFO, &cpu_count, &cpuinfo, &cpuinfo_count) == KERN_SUCCESS) { - static processor_info_array_t s_cpuinfo_prev = tb_null; + static processor_info_array_t s_cpuinfo_prev = tb_null; static mach_msg_type_number_t s_cpuinfo_count_prev = 0; for (tb_int_t i = 0; i < cpu_count; ++i) { tb_int_t use, total; @@ -96,27 +96,27 @@ static tb_float_t xm_os_cpuinfo_usagerate() { if (s_cpuinfo_prev) { vm_deallocate(mach_task_self(), (vm_address_t)s_cpuinfo_prev, sizeof(integer_t) * s_cpuinfo_count_prev); } - s_time = tb_mclock(); - s_cpuinfo_prev = cpuinfo; + s_time = tb_mclock(); + s_cpuinfo_prev = cpuinfo; s_cpuinfo_count_prev = cpuinfo_count; } return cpu_count > 0 ? usagerate / cpu_count : 0; #elif defined(TB_CONFIG_OS_WINDOWS) // kernel include idle_time tb_float_t usagerate = 0; - FILETIME idle, kernel, user; + FILETIME idle, kernel, user; if (GetSystemTimes(&idle, &kernel, &user)) { - static FILETIME idle_prev = { 0 }; + static FILETIME idle_prev = { 0 }; static FILETIME kernel_prev = { 0 }; - static FILETIME user_prev = { 0 }; + static FILETIME user_prev = { 0 }; if (idle_prev.dwLowDateTime != 0 && idle_prev.dwHighDateTime != 0) { - tb_uint64_t idle_diff = xm_os_cpuinfo_subtract_times(&idle, &idle_prev); + tb_uint64_t idle_diff = xm_os_cpuinfo_subtract_times(&idle, &idle_prev); tb_uint64_t kernel_diff = xm_os_cpuinfo_subtract_times(&kernel, &kernel_prev); - tb_uint64_t user_diff = xm_os_cpuinfo_subtract_times(&user, &user_prev); + tb_uint64_t user_diff = xm_os_cpuinfo_subtract_times(&user, &user_prev); // kernel_time - idle_time = kernel_time, because kernel include idle_time - tb_uint64_t sys_total = kernel_diff + user_diff; + tb_uint64_t sys_total = kernel_diff + user_diff; tb_uint64_t kernel_total = kernel_diff - idle_diff; // sometimes kernel_time > idle_time @@ -125,7 +125,7 @@ static tb_float_t xm_os_cpuinfo_usagerate() { } } - idle_prev = idle; + idle_prev = idle; kernel_prev = kernel; user_prev = user; } @@ -135,8 +135,8 @@ static tb_float_t xm_os_cpuinfo_usagerate() { if (tb_file_info("/proc/stat", tb_null)) { FILE *fp = fopen("/proc/stat", "r"); if (fp) { - tb_char_t line[8192]; - static tb_int64_t total_prev = 0; + tb_char_t line[8192]; + static tb_int64_t total_prev = 0; static tb_int64_t active_prev = 0; while (!feof(fp)) { /* cpu 548760 0 867417 102226682 12430 0 9089 0 0 0 @@ -172,10 +172,10 @@ static tb_float_t xm_os_cpuinfo_usagerate() { &guest_nice)) { tb_int64_t active = (tb_int64_t)(user + nice + sys + irq + softirq + steal + guest + guest_nice); - tb_int64_t total = (tb_int64_t)(user + nice + sys + idle + iowait + irq + softirq + steal + + tb_int64_t total = (tb_int64_t)(user + nice + sys + idle + iowait + irq + softirq + steal + guest + guest_nice); if (total_prev > 0 && active_prev > 0) { - tb_int64_t total_diff = total - total_prev; + tb_int64_t total_diff = total - total_prev; tb_int64_t active_diff = active - active_prev; if (total_diff > 0) { usagerate = (tb_float_t)((tb_double_t)active_diff / total_diff); @@ -199,29 +199,29 @@ static tb_float_t xm_os_cpuinfo_usagerate() { #define CP_IDLE 4 #define CPUSTATES 5 - static tb_int64_t total_prev = 0; + static tb_int64_t total_prev = 0; static tb_int64_t active_prev = 0; - tb_float_t usagerate = 0; - long states[CPUSTATES] = { 0 }; - size_t states_size = sizeof(states); + tb_float_t usagerate = 0; + long states[CPUSTATES] = { 0 }; + size_t states_size = sizeof(states); if (sysctlbyname("kern.cp_time", &states, &states_size, tb_null, 0) == 0) { tb_long_t user = states[CP_USER]; tb_long_t nice = states[CP_NICE]; - tb_long_t sys = states[CP_SYS]; + tb_long_t sys = states[CP_SYS]; tb_long_t intr = states[CP_INTR]; tb_long_t idle = states[CP_IDLE]; tb_int64_t active = user + nice + sys + intr; - tb_int64_t total = user + nice + sys + idle + intr; + tb_int64_t total = user + nice + sys + idle + intr; if (total_prev > 0 && active_prev > 0) { - tb_int64_t total_diff = total - total_prev; + tb_int64_t total_diff = total - total_prev; tb_int64_t active_diff = active - active_prev; if (total_diff > 0) { usagerate = (tb_float_t)((tb_double_t)active_diff / total_diff); } } - total_prev = total; + total_prev = total; active_prev = active; } return usagerate; diff --git a/core/src/xmake/os/find.c b/core/src/xmake/os/find.c index 144ab4daa..aa40bf5bb 100644 --- a/core/src/xmake/os/find.c +++ b/core/src/xmake/os/find.c @@ -82,7 +82,7 @@ static tb_long_t xm_os_find_walk(tb_char_t const *path, tb_file_info_t const *in tb_bool_t excluded = tb_false; if (lua_istable(lua, 5)) { // the root directory - size_t rootlen = 0; + size_t rootlen = 0; tb_char_t const *rootdir = luaL_checklstring(lua, 1, &rootlen); tb_assert_and_check_return_val(rootdir && rootlen, TB_DIRECTORY_WALK_CODE_END); @@ -95,7 +95,7 @@ static tb_long_t xm_os_find_walk(tb_char_t const *path, tb_file_info_t const *in } // exclude paths - tb_int_t i = 0; + tb_int_t i = 0; tb_int_t count = (tb_int_t)lua_objlen(lua, 5); for (i = 0; i < count && !excluded; i++) { // get exclude diff --git a/core/src/xmake/os/getenvs.c b/core/src/xmake/os/getenvs.c index 1576c101d..bfe673438 100644 --- a/core/src/xmake/os/getenvs.c +++ b/core/src/xmake/os/getenvs.c @@ -103,12 +103,12 @@ static tb_void_t xm_os_getenvs_process_line(lua_State *lua, tb_char_t const *lin xm_os_getenvs_trim(&value_start, &value_end); // get key and value lengths - tb_size_t key_len = key_end - key_start; + tb_size_t key_len = key_end - key_start; tb_size_t value_len = value_end > value_start ? value_end - value_start : 0; // handle Windows-specific PATH conversion tb_char_t const *final_key_start = key_start; - tb_size_t final_key_len = key_len; + tb_size_t final_key_len = key_len; #if defined(TB_CONFIG_OS_WINDOWS) && !defined(TB_COMPILER_LIKE_UNIX) if (key_len == 4 && tb_strnicmp(key_start, "path", 4) == 0) { // use "PATH" instead of "path" @@ -134,9 +134,9 @@ tb_int_t xm_os_getenvs(lua_State *lua) { tb_wchar_t const *p = (tb_wchar_t const *)GetEnvironmentStringsW(); if (p) { tb_char_t *data = tb_null; - tb_size_t maxn = 0; - tb_char_t line[TB_PATH_MAXN]; - tb_size_t n = 0; + tb_size_t maxn = 0; + tb_char_t line[TB_PATH_MAXN]; + tb_size_t n = 0; while (*p) { n = tb_wcslen(p); if (n + 1 < tb_arrayn(line)) { diff --git a/core/src/xmake/os/meminfo.c b/core/src/xmake/os/meminfo.c index 44fbb7770..96db76f0d 100644 --- a/core/src/xmake/os/meminfo.c +++ b/core/src/xmake/os/meminfo.c @@ -62,7 +62,7 @@ static tb_bool_t xm_os_meminfo_stats(tb_int_t *ptotalsize, tb_int_t *pavailsize) vm_statistics64_data_t vmstat; mach_msg_type_number_t count = HOST_VM_INFO64_COUNT; if (host_statistics64(mach_host_self(), HOST_VM_INFO64, (host_info_t)&vmstat, &count) == KERN_SUCCESS) { - tb_int_t pagesize = (tb_int_t)tb_page_size(); + tb_int_t pagesize = (tb_int_t)tb_page_size(); tb_int64_t totalsize = (tb_int64_t)(vmstat.inactive_count + vmstat.free_count + vmstat.active_count + vmstat.wire_count #if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 @@ -94,15 +94,15 @@ static tb_bool_t xm_os_meminfo_stats(tb_int_t *ptotalsize, tb_int_t *pavailsize) if (fp) { // 8192 should be enough for the foreseeable future. tb_char_t buffer[8192]; - size_t len = fread(buffer, 1, sizeof(buffer) - 1, fp); + size_t len = fread(buffer, 1, sizeof(buffer) - 1, fp); if (!ferror(fp) && len) { tb_int64_t totalsize = xm_os_meminfo_get_value(buffer, "MemTotal:"); tb_int64_t availsize = xm_os_meminfo_get_value(buffer, "MemAvailable:"); if (availsize <= 0) { - tb_int64_t cachesize = xm_os_meminfo_get_value(buffer, "Cached:"); - tb_int64_t freesize = xm_os_meminfo_get_value(buffer, "MemFree:"); + tb_int64_t cachesize = xm_os_meminfo_get_value(buffer, "Cached:"); + tb_int64_t freesize = xm_os_meminfo_get_value(buffer, "MemFree:"); tb_int64_t buffersize = xm_os_meminfo_get_value(buffer, "Buffers:"); - tb_int64_t shmemsize = xm_os_meminfo_get_value(buffer, "Shmem:"); + tb_int64_t shmemsize = xm_os_meminfo_get_value(buffer, "Shmem:"); if (cachesize >= 0 && freesize >= 0 && buffersize >= 0 && shmemsize >= 0) { availsize = freesize + buffersize + cachesize - shmemsize; } @@ -110,7 +110,7 @@ static tb_bool_t xm_os_meminfo_stats(tb_int_t *ptotalsize, tb_int_t *pavailsize) if (totalsize > 0 && availsize >= 0) { *ptotalsize = (tb_int_t)(totalsize / 1024); *pavailsize = (tb_int_t)(availsize / 1024); - ok = tb_true; + ok = tb_true; } } fclose(fp); @@ -134,7 +134,7 @@ static tb_bool_t xm_os_meminfo_stats(tb_int_t *ptotalsize, tb_int_t *pavailsize) } #elif defined(TB_CONFIG_OS_BSD) && !defined(__OpenBSD__) unsigned long totalsize; - size_t size = sizeof(totalsize); + size_t size = sizeof(totalsize); if (sysctlbyname("hw.physmem", &totalsize, &size, tb_null, 0) != 0) { return tb_false; } diff --git a/core/src/xmake/os/readlink.c b/core/src/xmake/os/readlink.c index c1a45cf4b..87f4f0833 100644 --- a/core/src/xmake/os/readlink.c +++ b/core/src/xmake/os/readlink.c @@ -50,7 +50,7 @@ tb_int_t xm_os_readlink(lua_State *lua) { tb_char_t srcpath[TB_PATH_MAXN]; tb_long_t size = readlink(path, srcpath, TB_PATH_MAXN); if (size == TB_PATH_MAXN) { - tb_size_t maxn = TB_PATH_MAXN * 2; + tb_size_t maxn = TB_PATH_MAXN * 2; tb_char_t *data = (tb_char_t *)tb_malloc(maxn); if (data) { tb_long_t size = readlink(path, data, maxn); diff --git a/core/src/xmake/os/setenv.c b/core/src/xmake/os/setenv.c index be375b2f4..5e3744415 100644 --- a/core/src/xmake/os/setenv.c +++ b/core/src/xmake/os/setenv.c @@ -38,9 +38,9 @@ tb_int_t xm_os_setenv(lua_State *lua) { tb_assert_and_check_return_val(lua, 0); // get the name and value - size_t value_size = 0; - tb_char_t const *name = luaL_checkstring(lua, 1); - tb_char_t const *value = luaL_checklstring(lua, 2, &value_size); + size_t value_size = 0; + tb_char_t const *name = luaL_checkstring(lua, 1); + tb_char_t const *value = luaL_checklstring(lua, 2, &value_size); tb_check_return_val(name, 0); // set it diff --git a/core/src/xmake/os/syserror.c b/core/src/xmake/os/syserror.c index 3ef2a5c52..85309ac4d 100644 --- a/core/src/xmake/os/syserror.c +++ b/core/src/xmake/os/syserror.c @@ -37,7 +37,7 @@ tb_int_t xm_os_syserror(lua_State *lua) { tb_assert_and_check_return_val(lua, 0); // get syserror state - tb_int_t err = 0; + tb_int_t err = 0; tb_size_t syserror = tb_syserror_state(); switch (syserror) { case TB_STATE_SYSERROR_NOT_PERM: |
