From 96f25659541ce44f20770b8d6cd0f2ff62e3b0bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Grubbstr=C3=B6m=20=28Grubba=29?= <grubba@grubba.org> Date: Mon, 10 Feb 2020 14:21:55 +0100 Subject: [PATCH] I/O [NT]: Fixed some issues with debug_fd_openpty(). Setting the window size should now work. --- src/configure.in | 10 +++++++++- src/fdlib.c | 15 +++++++++++++-- src/fdlib.h | 9 ++++++++- 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/src/configure.in b/src/configure.in index 81404eb6e0..09b0e5379d 100644 --- a/src/configure.in +++ b/src/configure.in @@ -3308,9 +3308,17 @@ AC_CHECK_HEADERS(winsock2.h sys/rusage.h time.h sys/time.h sys/types.h \ #ifdef HAVE_SYS_PARAM_H # include <sys/param.h> #endif +/* Necessary to find struct winsize. */ +#ifdef HAVE_TERMIOS_H +#include <termios.h> +#elif defined(HAVE_SYS_TERMIOS_H) +/* NB: Deprecated by <termios.h> above. */ +#include <sys/termios.h> +#endif ]) -AC_CHECK_TYPES([HPCON, LPPROC_THREAD_ATTRIBUTE_LIST, LPSTARTUPINFOEXW],,,[ +AC_CHECK_TYPES([HPCON, LPPROC_THREAD_ATTRIBUTE_LIST, LPSTARTUPINFOEXW, + struct winsize],,,[ #if (defined(__WINNT__) || defined(__WIN32__)) && !defined(__NT__) #define __NT__ #endif diff --git a/src/fdlib.c b/src/fdlib.c index 13d4d4b8a7..680dbcf85c 100644 --- a/src/fdlib.c +++ b/src/fdlib.c @@ -2775,12 +2775,14 @@ PMOD_EXPORT const char *debug_fd_inet_ntop(int af, const void *addr, PMOD_EXPORT int debug_fd_openpty(int *master, int *slave, char *ignored_name, void *ignored_term, - void *ignored_winp) + struct winsize *winp) { struct my_pty *master_pty = NULL; struct my_pty *slave_pty = NULL; int master_fd = -1; int slave_fd = -1; + COORD sz; + if (!Pike_NT_CreatePseudoConsole) { errno = ENOENT; return -1; @@ -2817,9 +2819,18 @@ PMOD_EXPORT int debug_fd_openpty(int *master, int *slave, goto fail; } + /* Some reasonable defaults. */ + sz.X = 80; + sz.Y = 25; + + if (winp) { + sz.X = winp->ws_col; + sz.y = winp->ws_row; + } + if (FAILED(Pike_NT_CreatePseudoConsole(sz, slave_pty->write_pipe, slave_pty->read_pipe, - 0, &master->pty))) { + 0, &master_pty->conpty))) { goto fail; } diff --git a/src/fdlib.h b/src/fdlib.h index 7d5c301e4e..74bfdf3ce0 100644 --- a/src/fdlib.h +++ b/src/fdlib.h @@ -109,6 +109,13 @@ typedef struct _STARTUPINFOEXW } STARTUPINFOEXW, *LPSTARTUPINFOEXW; #endif +#ifndef HAVE_STRUCT_WINSIZE +/* Typically found in <termios.h>. */ +struct winsize { + unsigned short ws_row, ws_col, ws_xpixel, ws_ypixel; +}; +#endif + #define SOCKFUN1(NAME,T1) PMOD_EXPORT int PIKE_CONCAT(debug_fd_,NAME) (FD,T1); #define SOCKFUN2(NAME,T1,T2) PMOD_EXPORT int PIKE_CONCAT(debug_fd_,NAME) (FD,T1,T2); #define SOCKFUN3(NAME,T1,T2,T3) PMOD_EXPORT int PIKE_CONCAT(debug_fd_,NAME) (FD,T1,T2,T3); @@ -214,7 +221,7 @@ PMOD_EXPORT const char *debug_fd_inet_ntop(int af, const void *addr, PMOD_EXPORT int debug_fd_openpty(int *master, int *slave, char *ignored_name, void *ignored_term, - void *ignored_winp); + struct winsize *winp); /* Prototypes end here */ #undef SOCKFUN1 -- GitLab