summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2020-02-21 22:47:02 +0800
committerruki <[email protected]>2020-02-21 10:42:12 +0800
commit868450acbb14b1bf5cd2da7b1b09a195e88a6bd5 (patch)
tree1f819dfe83532688d67f417069ffa4d0246d3933
parentfd61c350299a4d888bb3e81594077224e5fb4252 (diff)
improve strerror and os
m---------core/src/tbox/tbox0
-rw-r--r--core/src/xmake/os/cpfile.c4
-rw-r--r--core/src/xmake/os/strerror.c20
-rw-r--r--xmake/core/base/os.lua7
4 files changed, 16 insertions, 15 deletions
diff --git a/core/src/tbox/tbox b/core/src/tbox/tbox
-Subproject 37ba0093d152b0d892925aee0e0d7b2ea66360c
+Subproject 14b85615dda8a1daf8abdef8883627be6432e86
diff --git a/core/src/xmake/os/cpfile.c b/core/src/xmake/os/cpfile.c
index e896c1136..b3aa56f4d 100644
--- a/core/src/xmake/os/cpfile.c
+++ b/core/src/xmake/os/cpfile.c
@@ -43,9 +43,7 @@ tb_int_t xm_os_cpfile(lua_State* lua)
tb_char_t const* dst = luaL_checkstring(lua, 2);
tb_check_return_val(src && dst, 0);
- // done os.cpfile(src, dst)
+ // do copy
lua_pushboolean(lua, tb_file_copy(src, dst));
-
- // ok
return 1;
}
diff --git a/core/src/xmake/os/strerror.c b/core/src/xmake/os/strerror.c
index 399f0dedd..1a88546ec 100644
--- a/core/src/xmake/os/strerror.c
+++ b/core/src/xmake/os/strerror.c
@@ -29,9 +29,7 @@
* includes
*/
#include "prefix.h"
-#ifdef TB_CONFIG_OS_WINDOWS
-# include <windows.h>
-#else
+#if !defined(TB_CONFIG_OS_WINDOWS) || defined(TB_COMPILER_LIKE_UNIX)
# include <errno.h>
# include <string.h>
#endif
@@ -44,13 +42,17 @@ tb_int_t xm_os_strerror(lua_State* lua)
// check
tb_assert_and_check_return_val(lua, 0);
- // done os.strerror()
-#ifdef TB_CONFIG_OS_WINDOWS
- lua_pushstring(lua, tb_state_cstr(tb_syserror_state()));
+ // get syserror state
+ tb_size_t syserror = tb_syserror_state();
+ if (syserror != TB_STATE_SYSERROR_UNKNOWN_ERROR)
+ lua_pushstring(lua, tb_state_cstr(syserror));
+ else
+ {
+#if defined(TB_CONFIG_OS_WINDOWS) && !defined(TB_COMPILER_LIKE_UNIX)
+ lua_pushstring(lua, tb_state_cstr(syserror));
#else
- lua_pushstring(lua, strerror(errno));
+ lua_pushstring(lua, strerror(errno));
#endif
-
- // ok
+ }
return 1;
}
diff --git a/xmake/core/base/os.lua b/xmake/core/base/os.lua
index 6b1366ac8..de67d636b 100644
--- a/xmake/core/base/os.lua
+++ b/xmake/core/base/os.lua
@@ -440,8 +440,9 @@ function os.rm(...)
-- remove directories
for _, filedir in ipairs(os.argw(args)) do
- if not os._rm(filedir) then
- return false, string.format("remove: %s failed!", filedir)
+ local ok, errors = os._rm(filedir)
+ if not ok then
+ return false, errors
end
end
@@ -455,7 +456,7 @@ function os.ln(filedir, symfile)
return false, string.format("symlink is not supported!")
end
if not os.link(filedir, symfile) then
- return false, string.format("link %s to %s failed!", filedir, symfile)
+ return false, string.format("cannot link %s to %s, error: %s", filedir, symfile, os.strerror())
end
return true
end