From 95f7e64a45ac3fd84e21c0e0c6ebe4c31d372a37 Mon Sep 17 00:00:00 2001 From: ruki Date: Thu, 7 Sep 2017 13:10:38 +0800 Subject: impl isatty for windows --- core/src/xmake/io/isatty.c | 19 ++++++++++--------- 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 +#else # include #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 -- cgit v1.3.1