diff options
| author | ruki <[email protected]> | 2017-09-07 13:10:38 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2017-09-07 13:10:38 +0800 |
| commit | 95f7e64a45ac3fd84e21c0e0c6ebe4c31d372a37 (patch) | |
| tree | f8be4f717a7c235188997a6de68cd897a2eef0f9 | |
| parent | f7fe93d37dd1e863a09c0d41f7ec74200cc9242c (diff) | |
impl isatty for windows
| -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 |
