From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2155) id BF02D3857C75; Thu, 28 Jan 2021 10:25:28 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BF02D3857C75 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Corinna Vinschen To: cygwin-cvs@sourceware.org Subject: [newlib-cygwin] Cygwin: pty: Keep code page between non-cygwin apps. X-Act-Checkin: newlib-cygwin X-Git-Author: Takashi Yano via Cygwin-patches X-Git-Refname: refs/heads/master X-Git-Oldrev: 10d083c745dd89e824adc960d555975afc26b785 X-Git-Newrev: 442093214dd6b911a3a0080a10904587733a581f Message-Id: <20210128102528.BF02D3857C75@sourceware.org> Date: Thu, 28 Jan 2021 10:25:28 +0000 (GMT) X-BeenThere: cygwin-cvs@cygwin.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Cygwin core component git logs List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 28 Jan 2021 10:25:28 -0000 https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=442093214dd6b911a3a0080a10904587733a581f commit 442093214dd6b911a3a0080a10904587733a581f Author: Takashi Yano via Cygwin-patches Date: Thu Jan 28 12:26:12 2021 +0900 Cygwin: pty: Keep code page between non-cygwin apps. - After commit bb428520, there has been the disadvantage: 4) Code page cannot be changed by chcp.com. Acctually, chcp works itself and changes code page of its own pseudo console. However, since pseudo console is recreated for another process, it cannot inherit the code page. This patch clears this disadvantage. Diff: --- winsup/cygwin/fhandler_tty.cc | 7 +++++++ winsup/cygwin/tty.cc | 2 ++ winsup/cygwin/tty.h | 2 ++ 3 files changed, 11 insertions(+) diff --git a/winsup/cygwin/fhandler_tty.cc b/winsup/cygwin/fhandler_tty.cc index f0b2cd60a..34cff2ae5 100644 --- a/winsup/cygwin/fhandler_tty.cc +++ b/winsup/cygwin/fhandler_tty.cc @@ -2845,6 +2845,11 @@ fhandler_pty_slave::setup_pseudoconsole (bool nopcon) HPCON_INTERNAL *hp = (HPCON_INTERNAL *) get_ttyp ()->h_pseudo_console; get_ttyp ()->h_pcon_write_pipe = hp->hWritePipe; } + + if (get_ttyp ()->previous_code_page) + SetConsoleCP (get_ttyp ()->previous_code_page); + if (get_ttyp ()->previous_output_code_page) + SetConsoleOutputCP (get_ttyp ()->previous_output_code_page); return true; cleanup_pcon_in: @@ -2884,6 +2889,8 @@ fhandler_pty_slave::close_pseudoconsole (tty *ttyp) if (ttyp->h_pseudo_console) { ttyp->wait_pcon_fwd (); + ttyp->previous_code_page = GetConsoleCP (); + ttyp->previous_output_code_page = GetConsoleOutputCP (); FreeConsole (); AttachConsole (ATTACH_PARENT_PROCESS); HPCON_INTERNAL *hp = (HPCON_INTERNAL *) ttyp->h_pseudo_console; diff --git a/winsup/cygwin/tty.cc b/winsup/cygwin/tty.cc index 436f5c6c3..908166a37 100644 --- a/winsup/cygwin/tty.cc +++ b/winsup/cygwin/tty.cc @@ -246,6 +246,8 @@ tty::init () has_csi6n = false; need_invisible_console = false; invisible_console_pid = 0; + previous_code_page = 0; + previous_output_code_page = 0; } HANDLE diff --git a/winsup/cygwin/tty.h b/winsup/cygwin/tty.h index eb604588c..061357437 100644 --- a/winsup/cygwin/tty.h +++ b/winsup/cygwin/tty.h @@ -107,6 +107,8 @@ private: bool has_csi6n; bool need_invisible_console; pid_t invisible_console_pid; + UINT previous_code_page; + UINT previous_output_code_page; public: HANDLE from_master () const { return _from_master; }