diff options
| -rw-r--r-- | core/src/xmake/io/isatty.c | 19 | ||||
| -rw-r--r-- | core/src/xmake/machine.c | 1 |
2 files changed, 11 insertions, 9 deletions
diff --git a/core/src/xmake/io/isatty.c b/core/src/xmake/io/isatty.c index a210771a4..e094ebcfc 100644 --- a/core/src/xmake/io/isatty.c +++ b/core/src/xmake/io/isatty.c @@ -33,7 +33,9 @@ * includes */ #include "prefix.h" -#ifndef TB_CONFIG_OS_WINDOWS +#ifdef TB_CONFIG_OS_WINDOWS +# include <io.h> +#else # include <unistd.h> #endif @@ -50,16 +52,15 @@ tb_int_t xm_io_isatty(lua_State* lua) // check tb_assert_and_check_return_val(lua, 0); + // get file pointer + FILE** fp = (FILE**)luaL_checkudata(lua, 1, LUA_FILEHANDLE); + // no arguments? default: stdout tb_int_t answer = 1; -#ifndef TB_CONFIG_OS_WINDOWS - if (lua_gettop(lua) == 0) - answer = isatty(1); - else - { - FILE** fp = (FILE**)luaL_checkudata(lua, 1, LUA_FILEHANDLE); - if (fp) answer = isatty(fileno(*fp)); - } +#ifdef TB_CONFIG_OS_WINDOWS + if (fp) answer = _isatty(_fileno(*fp)); +#else + if (fp) answer = isatty(fileno(*fp)); #endif // return answer diff --git a/core/src/xmake/machine.c b/core/src/xmake/machine.c index 34d80d618..09c496eaf 100644 --- a/core/src/xmake/machine.c +++ b/core/src/xmake/machine.c @@ -174,6 +174,7 @@ static luaL_Reg const g_os_functions[] = static luaL_Reg const g_io_functions[] = { { "isatty", xm_io_isatty } +, { tb_null, tb_null } }; // the path functions |
