summaryrefslogtreecommitdiff
path: root/core/src
diff options
context:
space:
mode:
authorTitanSnow <[email protected]>2017-04-30 16:54:40 +0800
committerTitanSnow <[email protected]>2017-04-30 16:54:40 +0800
commit831481cdfbf0905b543ad503950233d7736b97d6 (patch)
tree2281254737e2e8a4422b88d11ef93c7b8896ef33 /core/src
parentd60de990ac2b66c0f0a3d1956e14368a8ee82007 (diff)
fix when stdout is not a tty
Diffstat (limited to 'core/src')
-rw-r--r--core/src/xmake/os/getwinsize.c15
1 files changed, 10 insertions, 5 deletions
diff --git a/core/src/xmake/os/getwinsize.c b/core/src/xmake/os/getwinsize.c
index c541f1e0e..3f721c12f 100644
--- a/core/src/xmake/os/getwinsize.c
+++ b/core/src/xmake/os/getwinsize.c
@@ -35,8 +35,8 @@
#include "prefix.h"
#ifdef TB_CONFIG_OS_LINUX
#include <sys/ioctl.h>
-#include <termios.h>
-#include <unistd.h>
+#include <errno.h> // for errno
+#include <unistd.h> // for STDOUT_FILENO
#endif
/* //////////////////////////////////////////////////////////////////////////////////////
@@ -53,9 +53,14 @@ tb_int_t xm_os_getwinsize(lua_State* lua)
// get winsize
# ifdef TB_CONFIG_OS_LINUX
struct winsize size;
- ioctl(STDOUT_FILENO, TIOCGWINSZ, &size);
- w=size.ws_col;
- h=size.ws_row;
+ if(ioctl(STDOUT_FILENO, TIOCGWINSZ, &size)==0){
+ w=size.ws_col;
+ h=size.ws_row;
+ }else if(errno == ENOTTY)
+ w=h=-1; // set to INF if stdout is not a tty
+ //
+ // if stdout is a file there is no
+ // need to consider winsize limit
# endif
// done os.getwinsize()